Closed ghost closed 9 years ago
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.
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 https://github.com/zendesk/cross-storage/issues/20#issuecomment-156590190.
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?
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 https://github.com/zendesk/cross-storage/issues/20#issuecomment-156590916.
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.
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
The two scenarios I highlighted above will work with this quick fix.
The issue was twofold:
window.location.origin
is "file://"For consistency, you can specify an origin of /^file:\/\/$/
or .*
in the hub's permissions.
I understand this will work well with cross origin urls, but can it work with the file:// protocol or is a web server necessary?