<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>40068</bug_id>
          
          <creation_ts>2010-06-02 10:25:31 -0700</creation_ts>
          <short_desc>Second document.write() of external script fails</short_desc>
          <delta_ts>2022-08-14 14:16:41 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>CONFIGURATION CHANGED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tony Gentilcore">tonyg</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>abarth</cc>
    
    <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>bfulgham</cc>
    
    <cc>eric</cc>
    
    <cc>rniwa</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>233317</commentid>
    <comment_count>0</comment_count>
    <who name="Tony Gentilcore">tonyg</who>
    <bug_when>2010-06-02 10:25:31 -0700</bug_when>
    <thetext>The second document.write() of an external script fails. Here&apos;s a minimal test case.

This alerts &quot;[object HTMLScriptElement]&quot;, &quot;null&quot;:
&lt;script&gt;
    document.write(&apos;&lt;script src=ignored.js id=foo&gt;&lt;/scri&apos;+&apos;pt&gt;&apos;);
    alert(document.getElementById(&apos;foo&apos;));
    document.write(&apos;&lt;script src=ignored.js id=bar&gt;&lt;/scri&apos;+&apos;pt&gt;&apos;);
    alert(document.getElementById(&apos;bar&apos;));
&lt;/script&gt;

I&apos;d expect it to work like writing two inline scripts. This alerts &quot;[object HTMLScriptElement]&quot;, &quot;[object HTMLScriptElement]&quot;:
&lt;script&gt;
    document.write(&apos;&lt;script id=foo&gt;&lt;/scri&apos;+&apos;pt&gt;&apos;);
    alert(document.getElementById(&apos;foo&apos;));
    document.write(&apos;&lt;script id=bar&gt;&lt;/scri&apos;+&apos;pt&gt;&apos;);
    alert(document.getElementById(&apos;bar&apos;));
&lt;/script&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>233320</commentid>
    <comment_count>1</comment_count>
    <who name="Tony Gentilcore">tonyg</who>
    <bug_when>2010-06-02 10:34:54 -0700</bug_when>
    <thetext>Thinking about this more it makes some sense.

The first write causes the parser to be blocked by the external script. While the parser is blocked, the script continues executing. It executes the second document.write(), but its content is parser-blocked. Thus at the point the getElementById(&apos;bar&apos;) executes, the parsed source does not contain the &apos;bar&apos; script yet.

The only way to fix this would be to pause script execution until the external script executes. It isn&apos;t clear to me if that is the way it should work or if this is working as intended. Perhaps HTML5 defines this behavior? Thoughts?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>233357</commentid>
    <comment_count>2</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2010-06-02 11:31:37 -0700</bug_when>
    <thetext>Is this HTML5 only?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>233360</commentid>
    <comment_count>3</comment_count>
    <who name="Tony Gentilcore">tonyg</who>
    <bug_when>2010-06-02 11:33:04 -0700</bug_when>
    <thetext>This is without the HTML5 parser. I haven&apos;t tested it with HTML5.(In reply to comment #2)
&gt; Is this HTML5 only?

This is without HTML5. I haven&apos;t tried it with the HTML5 parser.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>233363</commentid>
    <comment_count>4</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2010-06-02 11:34:51 -0700</bug_when>
    <thetext>We should attach your test case to this bug, and see what the results are in firefox/IE.  This behavior may or may not be expected.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>233386</commentid>
    <comment_count>5</comment_count>
      <attachid>57680</attachid>
    <who name="Tony Gentilcore">tonyg</who>
    <bug_when>2010-06-02 12:25:26 -0700</bug_when>
    <thetext>Created attachment 57680
Testcase

IE8: PASS
Opera 10.5: PASS
FF3.6: RACE (passes reliably if an alert is placed after first write)
WebKit: FAIL</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1887793</commentid>
    <comment_count>6</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-07-29 16:59:57 -0700</bug_when>
    <thetext>All browsers (Safari 15.6, Chrome Canary 106 and Firefox Nightly 105 on macOS 12.5) match with each other in the attached test case and show &quot;FAIL&quot;. I am not sure on web-spec whether all browsers were wrong or it is just wrong behaviour across all b browsers but just wanted to share latest test results. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1891257</commentid>
    <comment_count>7</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2022-08-14 14:16:41 -0700</bug_when>
    <thetext>The test itself is now broken, as the written scripts don&apos;t show up in the DOM until later. But they do, and can be seen in Web Inspector in all browsers.

Still, this is fixed (config changed).</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>57680</attachid>
            <date>2010-06-02 12:25:26 -0700</date>
            <delta_ts>2010-06-02 12:25:26 -0700</delta_ts>
            <desc>Testcase</desc>
            <filename>doublewrite.html</filename>
            <type>text/html</type>
            <size>498</size>
            <attacher name="Tony Gentilcore">tonyg</attacher>
            
              <data encoding="base64">PGh0bWw+Cjxib2R5PgpUZXN0cyB0aGUgYmVoYXZpb3Igb2Ygd3JpdGluZyB0d28gZXh0ZXJuYWwg
c2NyaXB0IGJsb2Nrcy4gU2hvdWxkIHByaW50ICdQQVNTJy4KPGhyPgoKPHNjcmlwdD4KICAgIHZh
ciBmb29TY3JpcHQsIGJhclNjcmlwdDsKICAgIGRvY3VtZW50LndyaXRlKCc8c2NyaXB0IHNyYz1p
Z25vcmVkLmpzIGlkPWZvbz48L3NjcmknKydwdD4nKTsKICAgIGZvb1NjcmlwdCA9IGRvY3VtZW50
LmdldEVsZW1lbnRCeUlkKCdmb28nKTsKICAgIGRvY3VtZW50LndyaXRlKCc8c2NyaXB0IHNyYz1p
Z25vcmVkLmpzIGlkPWJhcj48L3NjcmknKydwdD4nKTsKICAgIGJhclNjcmlwdCA9IGRvY3VtZW50
LmdldEVsZW1lbnRCeUlkKCdiYXInKTsKCiAgICBpZiAoZm9vU2NyaXB0ICYmIGJhclNjcmlwdCkK
ICAgICAgICBkb2N1bWVudC53cml0ZSgnUEFTUycpOwogICAgZWxzZQogICAgICAgIGRvY3VtZW50
LndyaXRlKCdGQUlMJyk7Cjwvc2NyaXB0Pgo8L2JvZHk+CjwvaHRtbD4K
</data>

          </attachment>
      

    </bug>

</bugzilla>