Open Bug 1950572 Opened 1 year ago Updated 1 year ago

iframe added during onafterprint is never loaded

Categories

(Core :: DOM: Navigation, defect)

Firefox 135
defect

Tracking

()

People

(Reporter: shlomo, Unassigned)

References

(Depends on 1 open bug)

Details

(Keywords: parity-chrome)

Attachments

(1 file)

Steps to reproduce:

The following document has an iframe with the contents "A" which is printed on load.
After closing the Print dialog, a second iframe with the contents "B" should be added to the document.

<!doctype html>
<iframe id="a" srcdoc="A"></iframe>
<script>
function addIFrame() {
const b = document.createElement("iframe");
b.onload = () => { console.log("b onload"); }
b.srcdoc = "B";
document.body.appendChild(b);
}

const a = document.getElementById("a");
a.onload = () => {
    a.contentWindow.onafterprint = addIFrame;

    // WORKAROUND:
    // a.contentWindow.onafterprint = setTimeout(() => { addIFrame(); });

    a.contentWindow.print();
}

</script>

Actual results:

The second iframe is empty (and its onload event never runs).

Expected results:

The second iframe has the contents "B" (and its onload event runs).
This works on Chromium.
On Firefox, I need to call setTimeout as a workaround (see commented-out line above).

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Core & HTML' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Attached file testcase

Indeed, it works on Chrome, but not on Firefox.

Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Unspecified → All
Hardware: Unspecified → All

Sean, do you have any ideas?

Component: DOM: Core & HTML → DOM: Navigation
Flags: needinfo?(sefeng)
Keywords: parity-chrome

We don't allow navigation when the top BC is in printing mode https://searchfox.org/mozilla-central/rev/80ae03d93e3fd5769b16f37719b610e359f8fc62/docshell/base/nsDocShell.cpp#3047

Emilio, thoughts...?

Flags: needinfo?(sefeng) → needinfo?(emilio)

(I think afterprint should be dispatched to notify web apps of ending the printing mode, so, any printing mode limitation shouldn't be applied at least. Ideally, the pending navigation should start before or after that.)

Bug 1663290 is on file to consider changing when we dispatch afterprint. Probably that fixes this use-case.

Depends on: 1663290
Flags: needinfo?(emilio)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: