public
Created

history.replaceState testcase HTML file by Matt Kruse

  • Download Gist
replaceStateTestPage.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
<!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>
replaceStateTestScript.user.js
JavaScript
1 2 3 4 5 6 7
// ==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);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.