Closed Bug 644034 Opened 13 years ago Closed 13 years ago

Cloning a script node clones its "already started" flag (per HTML5)

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: matthew.donofrio, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16
Build Identifier: 

When you attach a script node to the DOM in the following manner:

var div = document.createElement('div');
div.innerHTML = '<scr'+'ipt type="text/javascript" src="http://www.google-analytics.com/ga.js?wtf"></sc'+'ript>';
var script = parser.firstChild.cloneNode(true);
document.getElementsByTagName('head')[0].appendChild(script);

The script is attached but the request for the external file is not made.  FF3.6, Safari 5, IE<9 and Chrome 10 make the request and execute the code.  

Reproducible: Always

Steps to Reproduce:
1. Visit http://jsbin.com/ohoze4/5
2. You will see that ga.js does not load
3.
Actual Results:  
ga.js is not requested or executed

Expected Results:  
ga.js should be downloaded and executed when that script node is attached to the DOM
Might this be fallout from this?
http://hsivonen.iki.fi/script-execution/

The testcase URL doesn't work for me in Chrome 11.0.696.16 dev either.
Component: General → DOM: Core & HTML
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → Trunk
I read this article a while back and revisited it after finding this; nothing jumped out at me.  

The test case works for me in Chrome 11.0.696.16 Beta on Linux.
OS: Windows 7 → Windows XP
(In reply to comment #0)
> var div = document.createElement('div');
> div.innerHTML = '<scr'+'ipt type="text/javascript"
> src="http://www.google-analytics.com/ga.js?wtf"></sc'+'ript>';

This creates a script node that has been marked as "already started", per the HTML5 spec.

> var script = parser.firstChild.cloneNode(true);

Don't you mean div.firstChild?

If so, this creates a new script node that has a copy of the flags of the original and, hence, is also marked "already started". Again, per the HTML5 spec

> document.getElementsByTagName('head')[0].appendChild(script);

There is no attempt to execute the script, because it has been marked "already started".

So is HTML5 wrong when it says cloning a script clones the "already started" flag.

(In reply to comment #1)
> Might this be fallout from this?
> http://hsivonen.iki.fi/script-execution/

Not this time!

Better test case:
http://hsivonen.iki.fi/test/moz/clone-script.html
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Attaching script node with src does not request script → Cloning a script node clones its "already started" flag (per HTML5)
This is a surprising interaction of the spec taking the flag cloning from old Gecko behavior while taking the innerHTML behavior from the old WebKit behavior.

I'm inclined to WONTFIX, since both potential fixes are bad.
Reporter, does this break a real site somewhere?
>> var div = document.createElement('div');
>> div.innerHTML = '<scr'+'ipt type="text/javascript"
>> src="http://www.google-analytics.com/ga.js?wtf"></sc'+'ript>';

> This creates a script node that has been marked as "already started", per the
> HTML5 spec.

Why does FF4 set the "already started" flag when appending a script node to a HTMLDivElement not in a Document?

> This is a surprising interaction of the spec taking the flag cloning from old
> Gecko behavior while taking the innerHTML behavior from the old WebKit
> behavior.

Ah, ok.  This explains why I had to use cloneNode to make in Webkit work.

> Reporter, does this break a real site somewhere?

This does not break a real site.  I refactored my code to fix it.  Plenty of workarounds exist which satisfy my requirements.
> Why does FF4 set the "already started" flag when appending a script node to a
> HTMLDivElement not in a Document?

The "already started" flag is set on all script nodes created by an innerHTML setter, to prevent them running while innerHTML is being set.  Said prevention is needed for web compat....

Henri, I agree this is wontfix.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.