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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With