I would like to intercept location.reload();
via a Firefox API or by reading the JS on the page (remote & embedded) before it is loaded/executed or by any other means possible.
Example:
<head>
<script>
window.setTimeout(function() { location.reload(); }, 10000);
</script>
</head>
I have tried beforescriptexecute
event listener (via GreaseMonkey & // @run-at document-start
) but it is fired AFTER above is executed.
beforescriptexecute
works nicely on REMOTE scripts since the event beforescriptexecute
is fired before making the request (but then on the script src and not script content). It is different if the script is within normal script tag (and not remote), as per the example given. The beforescriptexecute
fires and the script content can be rewritten but by then the window.setTimeout()
has already fired and it is executing.
Another approach would be to verify whether a reload was initiated by the user (F5, refresh button etc in bowser scope) or via JavaScript on page-content scope.