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

location-changed event not fired in case of file:// protocol for mobile hybrid app. #59

Open
pkgulati opened this issue Nov 11, 2016 · 1 comment

Comments

@pkgulati
Copy link

Description

To check whether the href origin and current origin is same or not, URL constructor is being used.

URL constructor is behaving correctly for http:, but not for file: protocol

var url = new URL("http://google.com")
url.origin will be http://google.com

However when index.html is loaded from cordova hybrid app for following href
"file:///Users/kpraveen/Library/Developer/CoreSimulator/Devices/8336AC80-5CE3-4E95-BEDE-34667F0F845D/data/Containers/Bundle/Application/AA8F812B-2B08-41D9-A11C-F0E82B3B6193/HelloWorld.app/www/elements/abcd"
url.origin will be "null"

Due to this, when following check is performed
origin will be "file://", and url.origin will be "null"
if (url.origin !== origin) {
return null;
}
it will be treated as different origin, although origin is same.
This causes app-location, app-route to fail.
Tested in ios simulator on mac.

Expected outcome

if current and linked url both are from file:// it should be treated as same origin always and location-changed event must be fired.

Actual outcome

if current and linked url both are from file:// it is treated as cross origin so location-changed event is not fired.

@pkgulati pkgulati changed the title location-changed event not fired in case of file:// protocol in case of mobile hybrid app. location-changed event not fired in case of file:// protocol for mobile hybrid app. Nov 11, 2016
@pkgulati
Copy link
Author

I used following code to fix it for me.

    if (url._scheme === 'file' && origin === 'file://') {
         ;
    }
    else if (url.origin !== origin) {
          return null;
    }

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

1 participant