Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iframe.contentWindow always returns null #5500

Closed
Manishearth opened this issue Apr 3, 2015 · 8 comments
Closed

Iframe.contentWindow always returns null #5500

Manishearth opened this issue Apr 3, 2015 · 8 comments

Comments

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Apr 3, 2015

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

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Apr 3, 2015

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)

@magcius
Copy link

@magcius magcius commented Apr 3, 2015

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.

@jdm
Copy link
Member

@jdm jdm commented Apr 3, 2015

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

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Aug 11, 2015

@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.

@jdm
Copy link
Member

@jdm jdm commented Aug 11, 2015

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

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Aug 11, 2015

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

@jdm
Copy link
Member

@jdm jdm commented Aug 11, 2015

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

@Ms2ger
Copy link
Contributor

@Ms2ger Ms2ger commented Aug 18, 2015

@Ms2ger Ms2ger closed this Aug 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.