zendesk / cross-storage

Cross domain local storage, with permissions
Apache License 2.0
2.22k stars 180 forks source link

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

Closed ghost closed 9 years ago

ghost commented 9 years ago

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 commented 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.

ghost commented 9 years ago

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.

junosuarez commented 9 years ago

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 commented 9 years ago

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.

danielstjules commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

The issue was twofold:

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