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

Does it work with the file:// protocol? #20

Closed
ghost opened this issue Nov 13, 2015 · 7 comments
Closed

Does it work with the file:// protocol? #20

ghost opened this issue Nov 13, 2015 · 7 comments

Comments

@ghost
Copy link

ghost commented Nov 13, 2015

I understand this will work well with cross origin urls, but can it work with the file:// protocol or is a web server necessary?

@junosuarez
Copy link

Modern browsers treat file: URLs pretty restrictively and consider them to be different origins in most cases- see for example this note from MDN https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file%3A_URIs

However, you can use a light-weight development server such as node http-server or python SimpleHTTPServer and then access it over http://localhost which will be the same origin.

@ghost
Copy link
Author

ghost commented Nov 13, 2015

So it won't work with file:// protocol?

On 11/14/2015 05:03 AM, Jason Denizac wrote:

Modern browsers treat file: URLs pretty restrictively and consider
them to be different origins in most cases- see for example this note
from MDN
https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file%3A_URIs

However, you can use a light-weight development server such as node
http-server https://www.npmjs.com/package/http-server or python
SimpleHTTPServer
https://docs.python.org/2/library/simplehttpserver.html and then
access it over http://localhost which will be the same origin.


Reply to this email directly or view it on GitHub
#20 (comment).

@junosuarez
Copy link

I don't have a good test case in front of me, but I expect that it would not work. Could you describe your use case and what you're trying to achieve?

@ghost
Copy link
Author

ghost commented Nov 13, 2015

I have a multipage app(survey), which needs to store data until an
internet connection is available to upload it.
The multiple forms in my app are laid out as html files and can be
navigated via file:// protocol only, but due
to the same origin policy of indexeddb/localstorage, I can't use
pouchdb, taffyjs etc. Can cross-storage help me?
It says cross-origin requests are supported..

On 11/14/2015 05:07 AM, Jason Denizac wrote:

I don't have a good test case in front of me, but I expect that it
would not work. Could you describe your use case and what you're
trying to achieve?


Reply to this email directly or view it on GitHub
#20 (comment).

@danielstjules
Copy link
Contributor

http://localhost/client.html using file://path/to/hub.html will fail because browsers don't allow it.

file://client.html using http://localhost/hub.html will fail because message.origin is the string "null"
Same with file://client.html using http://localhost/hub.html
I can add support for those two cases above though.

@danielstjules
Copy link
Contributor

woops, should read:

file://client.html using http://localhost/hub.html will fail because message.origin is the string "null"
Same with file://client.html using file://localhost/hub.html

@danielstjules
Copy link
Contributor

The two scenarios I highlighted above will work with this quick fix.

The issue was twofold:

  • a posted message's origin will be the string "null" when the source is a "file://" This is odd, since window.location.origin is "file://"
  • The targetOrigin using postMessage must be set to "*" to target a file.

For consistency, you can specify an origin of /^file:\/\/$/ or .* in the hub's permissions.

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

2 participants