Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome SecurityError loading jQuery Mobile page from local file system

I get the following error in Chrome when loading a trivially simple html file with a jQuery Mobile reference. The error is not present with just the jQuery reference.

Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'http://stacksnippets.net/js' cannot be created in a document with origin 'null'.

<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
</head>
<body></body>
</html>

You can also "Run code snippet" and see the error in the console.

This error did not happen before today. I have not changed my code or method of loading the html file in the browser. It used to work perfectly - I use the same code for all my PhoneGap apps.

Does anyone know if there was a Chrome security update that causes this SecurityError or whether I'm missing something? How would you go about debugging this? Thank you.

UPDATE

This discussion I think points out what is going on, which I suspected, since the error does not appear when running with a web server: Origin null is not allowed by Access-Control-Allow-Origin .

But I am still wondering why this changed in the past day, whether Chrome has had a change in their security policy, or why it was working before, and whether any of my PhoneGap apps will be affected.

like image 800
raduation Avatar asked Mar 15 '23 21:03

raduation


2 Answers

This error is same as the origin is null error. This error occurs because of the security feature of Chrome. A simple solution to test the application is to bypass this security on chrome.

Steps:

  1. create a chrome browser shortcut on desktop.
  2. Close all the instances of chrome on your machine.
  3. Right click on the desktop shortcut of chrome and click on Properties.
  4. in Target field, append " -allow-file-access-from-files" at the end.
  5. Save and close properties.
  6. Open chrome via this shortcut only.

Hurry, the error has gone. App works perfectly.

NOTE: This is just a work-around I use to test my cordova apps on desktop browser for UI testing.

like image 84
saurabh Avatar answered Mar 17 '23 10:03

saurabh


Temporary solution: I've commented out all history.replaceState calls in jquery mobile, didn't need to manipulate browser history in my app anyways.

I wonder if it's chrome security bug or model and future behavior.

like image 29
t2n Avatar answered Mar 17 '23 09:03

t2n