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

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>20285</bug_id>
          
          <creation_ts>2012-12-07 07:22:23 +0000</creation_ts>
          <short_desc>document.open() should probably be ignored on documents that are not the current document in a browsing context</short_desc>
          <delta_ts>2012-12-31 05:16:39 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#opening-the-input-stream</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>yuhongbao_386</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>79619</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-12-07 07:22:23 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html
Multipage: http://www.whatwg.org/C#opening-the-input-stream
Complete: http://www.whatwg.org/c#opening-the-input-stream

Comment:
document.open() should probably be ignored on documents that are not the
current document in a browsing context

Posted from: 173.48.81.109 by bzbarsky@mit.edu
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:20.0) Gecko/20121203 Firefox/20.0</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79620</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-07 07:24:43 +0000</bug_when>
    <thetext>Gecko certainly ignores open() calls on random documents that have already been unloaded or are the result of a DOMParser parse invocation or whatnot. Not sure what other UAs do.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79675</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-07 22:05:18 +0000</bug_when>
    <thetext>The spec has some efforts at doing this already (e.g. not allowing it during unload); but I&apos;m happy to add more. Do you have any test cases showing this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79677</commentid>
    <comment_count>3</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-07 22:18:59 +0000</bug_when>
    <thetext>  var doc = new DOMParser().parseFromString(&quot;&lt;span&gt;&quot;, &quot;text/html&quot;)
  alert(doc.open());
  alert(doc.querySelector(&quot;span&quot;));

Or:

  var ifr = document.createElement(&quot;iframe&quot;);
  document.documentElement.appendChild(ifr);
  var doc = ifr.contentDocument;
  doc.open();
  doc.write(&quot;&lt;span&gt;&quot;);
  doc.close();
  ifr.parentNode.removeChild(ifr);
  alert(doc.open());
  alert(doc.querySelector(&quot;span&quot;));

Or:

  var ifr = document.createElement(&quot;iframe&quot;);
  document.documentElement.appendChild(ifr);
  var doc = ifr.contentDocument;
  doc.open();
  doc.write(&quot;&lt;span&gt;&quot;);
  doc.close();
  setTimeout(function(){
    ifr.onload = function() {
      alert(doc.querySelector(&quot;span&quot;));
      alert(doc.open());
      alert(doc.querySelector(&quot;span&quot;));
    };
    ifr.contentWindow.location = &quot;http://w3.org&quot;;
  }, 100);


Note that for all three of these the current spec makes no sense, since it talks about navigating and whatnot, but that assumes a browsing context. In particular, navigating in the third testcase would be pretty odd.

Note also that UA interop might not be great here.  ;)  In particular, I think Opera throws on the open() in all three cases, Gecko returns null and does nothing, WebKit clears out the DOM but doesn&apos;t do any obvious navigating.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79717</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-08 00:22:55 +0000</bug_when>
    <thetext>Yeah, the spec makes no sense here. It assumes the doc is active.

Looking at tests: Wow, there&apos;s just no interop here.

e.g. http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2006
 Opera: replaces the currently rendered page with the new text (!)
 WebKit: nukes the doc, writes to it off-screen
 Gecko: does nothing (ignores .open and .write calls)

Should I just abort if the doc is not the active document of its browsing context, or if it has no browsing context? Or just wrap the stuff that only makes sense for active docs with a check that the doc is active?

I should probably test IE before deciding, based on the total lack of interop I&apos;ve seen so far.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79727</commentid>
    <comment_count>5</comment_count>
    <who name="Yuhong Bao">yuhongbao_386</who>
    <bug_when>2012-12-08 01:03:41 +0000</bug_when>
    <thetext>IE10RP Win7:
log: object &quot;[object Document]&quot; (259 props: doctype=&quot;null&quot;, documentElement=&quot;null&quot;, implementation=&quot;[object DOMImplementation]&quot;, inputEncoding=&quot;UTF-8&quot;...)
log: undefined
log: object &quot;null&quot; (0 props)
log: object &quot;[object HTMLPhraseElement]&quot; (272 props: cite=&quot;&quot;, dateTime=&quot;&quot;, currentStyle=&quot;[object MSCurrentStyleCSSProperties]&quot;, runtimeStyle=&quot;[object MSStyleCSSProperties]&quot;...)
IFRAME says &quot;hello!&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79728</commentid>
    <comment_count>6</comment_count>
    <who name="Yuhong Bao">yuhongbao_386</who>
    <bug_when>2012-12-08 01:04:12 +0000</bug_when>
    <thetext>In IE10 mode.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79729</commentid>
    <comment_count>7</comment_count>
    <who name="Yuhong Bao">yuhongbao_386</who>
    <bug_when>2012-12-08 01:06:19 +0000</bug_when>
    <thetext>For http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=2007</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79730</commentid>
    <comment_count>8</comment_count>
    <who name="Yuhong Bao">yuhongbao_386</who>
    <bug_when>2012-12-08 01:10:57 +0000</bug_when>
    <thetext>Just tried this again in the same browser and it says &quot;error: Permission denied on line 10&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79731</commentid>
    <comment_count>9</comment_count>
    <who name="Yuhong Bao">yuhongbao_386</who>
    <bug_when>2012-12-08 01:12:46 +0000</bug_when>
    <thetext>And / is displayed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79732</commentid>
    <comment_count>10</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-08 01:15:42 +0000</bug_when>
    <thetext>&gt; Should I just abort if the doc is not the active document of its browsing
&gt; context, or if it has no browsing context?

That&apos;s my preference, obviously, but I might be biased by that being what Gecko does and simple to implement.

&gt; Or just wrap the stuff that only makes sense for active docs with a check that
&gt; the doc is active?

That would probably be OK too, but implementing in practice might be a pain.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79738</commentid>
    <comment_count>11</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-12-08 03:28:57 +0000</bug_when>
    <thetext>IE apparently does what Opera does. I don&apos;t understand how that happens.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79739</commentid>
    <comment_count>12</comment_count>
    <who name="Yuhong Bao">yuhongbao_386</who>
    <bug_when>2012-12-08 03:43:29 +0000</bug_when>
    <thetext>It seems to depend on timing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80768</commentid>
    <comment_count>13</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-12-31 05:16:39 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r7626.
Check-in comment: Make document.open() do nothing on non-active documents
http://html5.org/tools/web-apps-tracker?from=7625&amp;to=7626</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>