Created
June 1, 2012 06:04
-
-
Save qufighter/2849384 to your computer and use it in GitHub Desktop.
history.replaceState testcase HTML file by Matt Kruse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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