How to read/intercept JavaScript on the page before it is executed?
<p>I would like to intercept <code>location.reload();</code> via a Firefox API or by reading the JS on the page (remote &amp; embedded) before it is loaded/executed or by any other means possible.</p>

<p>Example:</p>

<pre><code>&lt;head&gt;
    &lt;script&gt;
        window.setTimeout(function() { location.reload(); }, 10000);
    &lt;/script&gt;
&lt;/head&gt;
</code></pre>

<p>I have tried <code>beforescriptexecute</code> event listener (via GreaseMonkey &amp; <code>// @run-at document-start</code>) but it is fired AFTER above is executed.</p>

<p><strong>Update:</strong>
<code>beforescriptexecute</code> works nicely on REMOTE scripts since the event <code>beforescriptexecute</code> 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 <code>beforescriptexecute</code> fires and the script content can be rewritten but by then the <code>window.setTimeout()</code> has already fired and it is executing.</p>