Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

History replaceState no longer working in Chrome for local file

I'm using window.history.replaceState() to change the query string of a HTML file that was accessed using file:///C:/...

This used to work in Chrome, Internet Explorer and FireFox, but no longer works in Chrome. Not sure when it stopped working. I have Chrome 45.0.2454.85. It still works in the other 2 browsers.

I am getting:

Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///C:/Users/Michael/Desktop/test.html?Q=NewQueryString' cannot be created in a document with origin 'null'.

Sorry, but this doesn't work in any hosted fiddle. You can copy the code to a local HTML file to see it for yourself:

<html>
<body>
<button onclick="clickme()">Click me</button>
<script>
function clickme() {
    window.history.replaceState({ "html": undefined, "pageTitle": "NewTitle"}, "", "?Q=NewQueryString");
}
</script>
</body>
</html>

Obviously I could host this on a server but was trying to keep simple. This is a simple scrum board that we are using hosted by Git. It hits a 3rd party web service to get the data. Any ideas on working around the error.

like image 643
Mike Avatar asked Sep 04 '15 12:09

Mike


2 Answers

It stopped working on Chrome 45. Here I filled an issue on code.google: https://code.google.com/p/chromium/issues/detail?id=529313

Setting the --allow-file-access-from-files is a good solution if you do just need to run it on your own computer.

like image 83
V_tredue Avatar answered Sep 22 '22 20:09

V_tredue


I had the same problem. As a workaround, I started Chrome with --allow-file-access-from-files flag.

But think this is not the best solution.

Below is an example of how I'm running:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --app=file: ///C:/APP/index.html --allow-file-access-from-files

If someone find a better solution, please let us know.

like image 31
Fabiano Aljava Avatar answered Sep 19 '22 20:09

Fabiano Aljava