Skip to content

Instantly share code, notes, and snippets.

@qufighter
Created June 1, 2012 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qufighter/2849384 to your computer and use it in GitHub Desktop.
Save qufighter/2849384 to your computer and use it in GitHub Desktop.
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