Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing error in WKWebView on iOS16 and above when building with Xcode14.3 #1324

Closed
3 tasks
tanukki2929 opened this issue May 10, 2023 · 9 comments
Closed
3 tasks

Comments

@tanukki2929
Copy link

Bug Report

Problem

What is expected to happen?

What does actually happen?

Routing error on iOS16 and above when building Angular app with Xcode14.3

ERROR Error: Uncaught (in promise): SecurityError: Blocked attempt to use history.pushState() to change session history URL from file:///Users/appname/Library/Developer/CoreSimulator/Devices/zzzzzzzz-yyyy-dddd-cccccc-bbbbbbbb/data/Containers/Bundle/Application/xxxxxxxx-yyyy-zzzz-wwww-aaaaaaaaaaaaa/APPNAME.app/index.html/ to file:///Users/appname/Library/Developer/CoreSimulator/Devices/zzzzzzzz-yyyy-dddd-cccccc-bbbbbbbb/data/Containers/Bundle/Application/xxxxxxxx-yyyy-zzzz-wwww-aaaaaaaaaaaaa/APPNAME.app/index.html/dashboard. Only differences in query and fragment are allowed for file: URLs.

The same problem reported in the APPLE forum below occurs.
Please let us know if there is any way to solve this problem with Cordova.
https://developer.apple.com/forums/thread/728157

Information

Command or Code

Environment, Platform, Device

Version information

Xcode バージョン 14.3 (14E222b)
"cordova-ios": "^6.3.0"

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@dpogue
Copy link
Member

dpogue commented May 10, 2023

The short answer is that you'll need to use a custom scheme instead of file URLs.

The long answer is that what you're trying to do doesn't make sense with file URLs and is actually forbidden by the HTML specification: https://html.spec.whatwg.org/multipage/history.html#can-have-its-url-rewritten

  1. If targetURL's scheme is "file", and targetURL and documentURL differ in their path component, then return false. (Differences in query and fragment are allowed for file: URLs.)

WebKit changed their behaviour in iOS 16.4 to match Chrome and the HTML spec: WebKit/WebKit@78a55cf


So it's fine to use pushState with file:/// URLs to go from index.html to index.html#/dashboard, but it is not allowed to go from index.html to index.html/dashboard.

Maybe your framework has an option to use hash-based URLs for routing?

@tanukki2929
Copy link
Author

Thank you for your response. I appreciate it very much.
We will see if we can address the issue based on your response.

@msmtamburro

This comment was marked as off-topic.

@jcesarmobile
Copy link
Member

It's not broken, I've just created a new app with cordova-ios 6.3.0 and it's working fine with a custom scheme.

@msmtamburro

This comment was marked as off-topic.

@jcesarmobile
Copy link
Member

In that case, can you create a new issue and provide a sample app that reproduces that issue?

But for regular use case, it's working fine.

@AlexBorsody
Copy link

AlexBorsody commented Jun 29, 2023

Running a Cordova app and ran across this same error in Xcode. I added this to my config.xml to set a custom URL scheme and it fixed the issue for me.

<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />

@sathishavunoori

This comment was marked as off-topic.

@breautek
Copy link
Contributor

The original reporter reported this issue in the context of using the history API with file:// protocol and answer on that subject is: #1324 (comment)

Hi, We are also having the same issue with our Cordova iOS app, our app is working on iOS 15 devices but when we run the same app on iOS 16.4 devices, the navigation from www/index.html to www/pages/ui/page1.html using $.mobile.changePage API is not working. Can any one suggest us how to fix this problem in cordova ios app with cordova-ios:6.3.0 or 7.0.0 versions with target SDK 16+

As noted above, if $.mobile.changePage is using the history API, then you either need to use schemes (see #1324 (comment)) or you need to use a hash-based routing. Without knowing what $.mobile.changePage actually does we can't provide further insights.

Closing as not-a-bug.

@breautek breautek closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants