Error: Attempt to run compile-and-go script on a cleared scope


Javascript Problem Overview

Since upgrading to Firefox 4.0, I've noticed that I'm occasionally getting an error in the console stating:

>attempt to run compile-and-go script on a cleared scope

The only information I can find about this on the net currently is on the mozilla groups forum, where it is suggested that it's something to do with session restoring. In my case, though I haven't been able to reliably reproduce the error, it happens at any time, not just after a restore.

What's the deal? How do I stop the error?

Javascript Solutions

Solution 1 - Javascript

For me (Firefox 11, Firebug 1.9.1) it happens sometimes after I refresh the page (either F5 or CTRL+F5) while debugger is paused on a breakpoint.

The solution seems to be to continue the execution of the script, and refresh the page only when Firebug is not paused.

Solution 2 - Javascript

In my case, it was document.write method causing the problem on Firefox 4, 5, 6 on Windows. Linux versions are unaffected. What I had to do is to overwrite document.write method.

I aware that document.write shouldn't be used these days, but deployJava.js, a standard Java Applet deployment script written by Sun/Oracle, is using it. Google is using it in Google AdSense ads. document.write is everywhere.

    var documentWriteOutput = '';
    var got = document.write;
    document.write = function(arg) { documentWriteOutput += arg; }
<script src="badScriptThatIsUsingDocumentWrite.js"></script>
    document.write = got;
    // Do whatever you want with the documentWriteOutput
    // e.g. $('#somewhere').html(documentWriteOutput);

I hope this helps. However, I saw lots of "solutions" on the Internet that didn't work for me. It may mean that "Attempt to run compile-and-go script on a cleared scope" is a Firefox JavaScript engine problem/bug.

Solution 3 - Javascript

I've noticed that this error can happen if you write to the document with document.write after the document has completed loading (e.g. in a function called from JQuery's $(document).ready() method). When this happens, it seems that Firefox discards the old document and writes a new one. I don't know if this is new behavior or not. It seems that when you try to operate on the old document, e.g. with JQuery selectors, you get this error. For me, fixing the script in question to not call document.write after the document had loaded fixed the error.

Solution 4 - Javascript

I have noticed that if I disable the cache, I no longer get this error in the console.

Solution 5 - Javascript

The error doesn't occur if Firebug (in my case 1.8) is disabled.

Solution 6 - Javascript

Check your code for duplicated meta cache-control and remove one of them:

<meta http-equiv="cache-control" content="no-cache" />

Solution 7 - Javascript

i had this problem too but I did a clean re-installation of FireFox.

after that the error was gone.

Solution 8 - Javascript

I got this error when I tried adding events on elements appended from a same domain iframe. Added clone() and errors stopped.

Solution 9 - Javascript

It has nothing to do with firebug. The reason it "goes away" when firebug is disabled is that you are no longer seeing the exception. The cause of this is having an handler attached to an event that is now null but not properly cleaned up. You need to make sure that handler is properly disposed of, otherwise the event still fires the reference to the handler.

Solution 10 - Javascript

It is: menu Firebug -> Console -> Show Chrome Errors

switch off, end of story ;)


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnickfView Question on Stackoverflow
Solution 1 - Javascriptjakub.gView Answer on Stackoverflow
Solution 2 - JavascriptNowakerView Answer on Stackoverflow
Solution 3 - JavascriptNate C-KView Answer on Stackoverflow
Solution 4 - JavascriptLiamView Answer on Stackoverflow
Solution 5 - JavascriptWolfgangView Answer on Stackoverflow
Solution 6 - JavascriptEneas GesingView Answer on Stackoverflow
Solution 7 - Javascriptuser1046787View Answer on Stackoverflow
Solution 8 - JavascriptkuldarView Answer on Stackoverflow
Solution 9 - JavascriptTerry BoswellView Answer on Stackoverflow
Solution 10 - Javascriptuser200346View Answer on Stackoverflow