3

The following is a stripped down version of a local file that I'm loading into Microsoft Edge:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>

    <script>
      var url = "http://example.com"

      // Document is ready
      ready(function () {
        var xhr = new XMLHttpRequest();
        xhr.open('POST', url, true)
        xhr.withCredentials = true
        xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8")
        xhr.onload = function() {
          console.log('onload')
          console.log('Status: ' + xhr.status + ". " + xhr.statusText)
        }
        xhr.onerror = function(error) {
          console.log('onerror')
        }
        xhr.send()
      })

      // Hook for when the DOM has finished loading
      function ready(fn) {
        if (document.readyState !== 'loading') {
          fn()
        } else {
          document.addEventListener('DOMContentLoaded', fn)
        }
      }
    </script>
  </head>
  <body>
  </body>
</html>

Loading it into the browser works great using file:///path/to/file.html and the request returns successfully. The problem that I'm running into is that the response is supposed to set a cookie in the browser. It works perfectly on Chrome, IE11, Firefox and Safari, but not on Edge.

Is there some sort of security measure in place preventing Edge from creating cookies from JavaScript that is run from a local file? If so, why?

docksteaderluke
  • 2,195
  • 5
  • 27
  • 38
  • Looks like if you can't create a cookie from another domain.. Simply a security policy? – Nico Jan 25 '16 at 16:16
  • I don't think so, because if I run the file hosted from localhost, or run the script on any other web page through the console, it works perfectly. – docksteaderluke Jan 25 '16 at 16:42
  • 3
    I have the same problem - I make an ajax request, the response contains a cookie. This cookie is not saved in Edge, but is saved in Chrome and Firefox – Zach Smith Feb 21 '18 at 08:30

1 Answers1

1

Microsoft Edge never save javascript cookies from

  • open local files direct, e.g. file://C:/test/index.html
  • domain containing underscores, e.g. test_a.mydomain.com

In order to test the cookie, a working environment must be created, e.g. localhost@xampp

devthune
  • 26
  • 3