sessionStorage in Javascript doesn't work in local

Issue #14157234 • Assigned to Shawn P.

Details

Author
Andre B.
Created
Oct 10, 2017
Privacy
This issue is public.
Found in
  • Microsoft Edge
Reports
Reported by 1 person

Sign in to watch or report this issue.

Steps to reproduce

sessionStorage in Javascript doesn’t work when I run a page in local without a server directly on a disk. Example:

file:///C:/UwAmp/ww…HTML/Example.html

but it works if you read the page via the network at the adress:
file://pc_tower/ww…HTML/Example.html

Regards
André

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Steven K.”

    • Hi Andre,

      I believe this is “working as designed” and is due to the ambiguity in local file’s URI origin.  Quoting the link below:

      "any two 

      file:
       URIs are considered to be same-origin.  In other words, any HTML file on your local disk can read any other file on your local disk."

      https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file:_URIs

      You should also see a javascript error in the console about the type issue.

      “SecurityError
      The request violates a policy decision, or the origin is not 
      a valid scheme/host/port tuple(this can happen if the origin uses the 
      file:
       
      or 
      data:
       
      scheme, for example). For example, the user may have their browser configured to deny permission to persist data for the specified origin.”

      https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

      If you want to use sessionStorage you could also host the file on a local web server.  This way the origin will not be ambiguous.  This method is common where an entry is added to the local hosts file to define the website’s domain under development.  localhost will also work.

      Hope this helps,

      Steve

    • Steven

      Thank you for your response but I think this is not due to a local file origin. I have just one file I launch directly from the windows file browser as this simple this one:

          Click to test SessionStorage
      

      I launch it in Edge at the adress:
      file:///C:/temp/test_session.html

      It generates an error with Edge and no error with Chrome or Firefox.

      I cannot instal a local web server as you suggest as my HTML pages are a product catalogue which is delivered on an USB key which must run without installation on the customer web browser.

      The only solution I see is to pass all the parameters from one page to another through the URL which less elegant than a sessionStorage.

      Regards

      André

    • The complete code of my previous message masked in a comment in order to avoid interpretation.

    • I am assuming you are not looking for a solution that persists data after the session, is that correct?  E.g. localStorage or IndexDB?

      Can you send me the error you are seeing?

      I found this work around for resources, perhaps related to sessionStorage.

      https://stackoverflow.com/questions/6898253/javascript-document-domain

      I will investigate if there is a solution without passing via URL and if this is really “working as designed.”

      Steve

    • Steven

      For you, to test my issue, I have put the few lines of code here:

      https://stackoverflow.com/questions/47289195/javascript-sessionstorage-in-local-with-edge

      Store the code on your loacal disk and test it with Edge to see the error in the console.

      Regards

      André

    • Hi Andre,

      Thank you for providing the repro.  I am able to repro this issue, however, I still believe this is “byDesign.”  I will investigate a bit more and let you know if anything changes in this regard.

      Appreciate the support with this issue,

      Steve

    • Microsoft Edge Team

      Changed Assigned To to “travil”

      Changed Assigned To to “Venkat K.”

      Changed Assigned To from “Venkat K.” to “Shawn P.”

    You need to sign in to your Microsoft account to add a comment.

    Sign in