Bug 55132 - DOMContentLoaded event is fired too early if scripts are inserted dynamically
Summary: DOMContentLoaded event is fired too early if scripts are inserted dynamically
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows 7
: P2 Normal
Assignee: Nobody
URL: http://www.zeit.de/politik/ausland/20...
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-24 04:15 PST by Wladimir Palant
Modified: 2011-09-10 09:25 PDT (History)
1 user (show)

See Also:


Attachments
Testcase (695 bytes, text/html)
2011-02-24 04:15 PST, Wladimir Palant
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wladimir Palant 2011-02-24 04:15:22 PST
Created attachment 83631 [details]
Testcase

It seems that WebKit's DOMContentLoaded event fails to consider dynamically inserted scripts properly. If a webpage inserts scripts dynamically during load Gecko and Opera will allow these scripts to run (they might still call document.write and such) and will only fire DOMContentLoaded event then. WebKit however ignores dynamically inserted scripts - DOMContentLoaded is fired immediately after the last "static" script finished executing. The attached testcase exemplifies this, it will check for two scripts whether they had a chance to run before DOMContentLoaded and "load" events. The expected result is that on DOMContentLoaded both scripts already executed - that's what I see in Firefox 3.6.13 and Opera 9.64. In Chrome 9.0.597.98 and Safari 4.0 however the dynamically inserted script didn't run on DOMContentLoaded, that is only the case when the "load" event is fired.

I originally came across this issue on http://www.zeit.de/politik/ausland/2011-02/libyen-gadhafi-proteste-staemme. The map there works by inserting a bunch of scripts into the document. One of these scripts will run on DOMContentLoaded (via jQuery.ready()) and expects the other scripts to be loaded. However, this isn't always the case in Chrome, it is rather a race condition.