Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
history.replaceState testcase HTML file by Matt Kruse
<!DOCTYPE html>
<html>
<head>
<title>replaceState Test for Greasemonkey</title>
<script>
window.addEventListener('DOMContentLoaded',function(){
window.history.replaceState(document.url, null);
},false);
</script>
</head>
<body>
<p>This test shows how GreaseMonkey incorrectly fires a script twice when a replaceState() call is made before the window is loaded.</p>
<p>Code in this document:</p>
<pre>
window.addEventListener('DOMContentLoaded',function(){
window.history.replaceState(document.url, null);
},false);
</pre>
<p>Test with this GM script:</p>
<pre>
// ==UserScript==
// @name Greasemonkey pushState test
// @namespace http://userscripts.org/users/86416
// @include http://socialfixer.com/temp/*
// @run-at document-start
// ==/UserScript==
alert("Greasemonkey test running: "+document.getElementsByTagName('BODY').length);
</pre>
<p>The problem does NOT happen when I monitor the window's "load" event rather than DOMContentLoaded.</p>
</body>
</html>
// ==UserScript==
// @name Greasemonkey pushState test
// @namespace http://userscripts.org/users/86416
// @include http://socialfixer.com/temp/*
// @run-at document-start
// ==/UserScript==
alert("Greasemonkey test running: "+document.getElementsByTagName('BODY').length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.