Closed Bug 1581901 Opened 5 years ago Closed 5 years ago

Iframe document reference lost in setTimeout callback

Categories

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

69 Branch
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 543435

People

(Reporter: edwin.andrivet.pro, Unassigned)

Details

Attachments

(1 file)

Attached file testcase.html (deleted) —

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:70.0) Gecko/20100101 Firefox/70.0

Steps to reproduce:

I noticed I had an empty iframe even with instructions in my code requiring this iframe document to be modified. I could isolate the problem in the setTimeout callback and could reproduce it with this basic JS example attached.
I tried two other global functions that use a callback with setInterval and addEventListener and the behavior is reproduced there too.

This was tested on Firefox 69.0 and Firefox Nightly (Build ID 20190917093629) on macos Mojave 10.14.6 and Ubuntu 18.04.3 LTS.

I couldn't find any issue related to this so hopefully this is not a duplicate.

Actual results:

Actual code: The document is untouched.
Sample code: Freshly retrieved document in setTimeout callback is different than the document reference above the call.

Expected results:

Actual code: The document should be modified.
Sample code: Freshly retrieved document in setTimeout callback should be equal to the document reference above the call.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

When iframe is added to document, initial about:blank document is created inside it, and then another document will load and replace it.

Flags: needinfo?(hsivonen)

As far as I can tell, comment 1 correctly identifies the cause. This is a long-standing and hard-to-fix problem in Gecko. Sorry.

I suggest not capturing the iframe in a closure and instead navigating from document to the iframe in the timeout.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Flags: needinfo?(hsivonen)
Resolution: --- → DUPLICATE

Bug 1447406 is GeckoView-specific...

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: