Dynamic script tags that are removed are still executed once script source is received




10 years ago
6 years ago


(Reporter: James Burke, Unassigned)


Firefox Tracking Flags

(Not tracked)


(Whiteboard: [CLOSEME 2010-11-01], URL)



10 years ago
User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv: Gecko/20070725 Firefox/
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv: Gecko/20070725 Firefox/

In general, scripts that have been removed from the DOM before they have been loaded by the browser should not be executed.

A script element with a src attribute is attached to the head element after the page loads. If that script element is removed from the DOM before the script source is processed by the browser, the browser will still execute the script source.

This causes problems with JSONP APIs (http://ajaxian.com/archives/jsonp-json-with-padding), where the callback specified in the script source may not exist once the script tag is removed.

This issue comes up if a JSONP API took a long time to respond, but the web page decided not to wait for it to complete. The web page may decide to remove the script tag and try the request again using some different parameters.

Reproducible: Always

Steps to Reproduce:
1. Go to test URL above.
2. Click "Start Test" button. A script tag will be added to the head element, but the JavaScript code will remove the script element 500 ms later. The URL the script element referenced in the source attribute will take about 5 seconds to complete.
3. If you have Firebug installed, you should see a "TEST OK. No errors should be seen after this timeout error." in the console. If no Firebug, the in-document Firebug lite should report the same thing.
Actual Results:  
After about 5 seconds, there will be an error in the Firebug console: "dojo.io.script.jsonp_dojoIoScript1 has no properties"

Also, if you click on the "Test for SuperXFooBarVariable". It will show an "Oh no" message because a global script variable named SuperXFooBarVariable was defined in the script source for the script element that was removed.

Expected Results:  
There should be no "dojo.io.script.jsonp_dojoIoScript1 has no properties" error after 5 seconds (or when the response for timeout.php is received). Also, after the 5 seconds, clicking on the "Test for SuperXFooBarVariable" variable should return something like "undefined".

Tested the above page with all Add-Ons turned off, and the issue still occurred.
This is a mass search for bugs that are in the Firefox General component, are
UNCO, and have not been changed for 800 days and have an unspecified version. 

Reporter, can you please update to Firefox 3.6.10, create a fresh profile,
http://support.mozilla.com/en-US/kb/managing+profiles, and test again. If you
still see the bug, please update this bug. If the issue is gone, please set the
resolution to RESOLVED > WORKSFORME.
Whiteboard: [CLOSEME 2010-11-01]
No reply from reporter, INCOMPLETE. Please retest with Firefox 3.6.12 or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Last Resolved: 7 years ago
Resolution: --- → INCOMPLETE

Comment 3

6 years ago
I am not the original bug reporter, but I've tested with FF 5.0.1 and just today with 8.0.1 on Mac OS X (Intel) and the bug is still present and should be reopened as unresolved.

Details of the problems along with testcases can be found  here: http://archive.dojotoolkit.org/nightly/dojotoolkit/dojo/tests/io/scriptTimeout.html  and here: http://bugs.jquery.com/ticket/8744

the basic problem is that FF does not cancel script loading after a script got removed from the DOM. This is, however, important as for JSONP requests a timeout may be set after which loading of the script is not necessary and will result in an "unknown function" error in FF if the callback has been freed in the meantime.
Bug 707154 was filed as a followup to comment 3.  Forward-dupping this, since that bug is clearer at this point....
Duplicate of bug: 707154
You need to log in before you can comment on or make changes to this bug.