I am trying to detect a page change on YouTube using history.pushState
, but it never works. Ultimately, I want this work to work with the Tampermonkey / Greasemonkey script, and for this I understand that you need to enter the script into the actual page, which I did so, but to no avail:
html = "var oldState = history.pushState;"+ "history.pushState = function() {" + "alert('url changed');" + "return oldState.apply(this);" + "}"; var head = document.getElementsByTagName("body")[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.innerHTML = html; head.appendChild(script);
I also tried running the same code from the debug console:
var oldState = history.pushState; history.pushState = function() { alert('url changed'); return oldState.apply(this); };
But it didn’t seem either. Does anyone have an idea of what is going on here?
source share