Skip to content

Iframe.contentWindow always returns null #5500

Closed

Description

@Manishearth

Testcase:

<html>
<head>
</head>
<body>
<iframe src='bar.html' id='foo'></iframe>

(bar.html is just an empty file on the same domain)
<script>
var ifr = document.getElementById('foo')
alert(ifr.contentWindow)
</script>
</body>

On running through gdb it seems like children here is an empty vector.

This happens to iframes created from source, from innerHTML, and from createElement()

cc @glennw @mbrubeck

Activity

  1. added
    A-content/dom
    I-wrong
    on Apr 3, 2015
  2. Manishearth commented on Apr 3, 2015

    @Manishearth
    MemberAuthor

    Update: this turns out to be because iframe loading is async, apparently

    However, i = document.createElement('iframe'); document.body.appendChild(i); i.contentWindow works in Firefox, but not in Servo (still gives null)

  3. magcius commented on Apr 3, 2015

    @magcius

    Right. It seems that the creation of the frame's document and window is deferred until the content is fetched -- and if no src is ever set, no content is ever fetched.

    If we set src to blank.html and instead fetch the contentWindow after a timeout, then it works fine.

    According to https://html.spec.whatwg.org/multipage/embedded-content.html#the-iframe-element , iframes without a src should have the src "about:blank", which is an immediately-available resource that can never asynchronously load.

  4. jdm commented on Apr 3, 2015

    @jdm
    Member

    Yes, sync about:blank is tracked at #5240.

  5. Manishearth commented on Aug 11, 2015

    @Manishearth
    MemberAuthor

    @sole has a nice example on #7162.

    Perhaps we should make the contentwindow getter block until the subpage exists? Have some sort of mutexy thing on the iframe that is locked when the fetch starts, and .contentWindow will block until it finishes.

  6. jdm commented on Aug 11, 2015

    @jdm
    Member

    No, we should just implement synchronous about:blank rather than hacking around the lack of it. That's #5240.

  7. Manishearth commented on Aug 11, 2015

    @Manishearth
    MemberAuthor

    That's only for iframes without a src. What about iframes with a src that haven't loaded yet?

  8. jdm commented on Aug 11, 2015

    @jdm
    Member

    Same deal. All iframes start with about:blank and then navigate to the src url.

  9. Ms2ger commented on Aug 18, 2015

    @Ms2ger
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-content/domI-wrong

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions