Closed Bug 1912881 Opened 1 year ago Closed 1 year ago

JavaScript Firefox print events not working

Categories

(Core :: DOM: UI Events & Focus Handling, defect)

Firefox 129
defect

Tracking

()

RESOLVED DUPLICATE of bug 1663290

People

(Reporter: Andreas, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Steps to reproduce:

=== 1 ===
window.addEventListener("beforeprint", () => calendarBeforePrint(calendarVariableName));
window.addEventListener("afterprint", () => calendarBeforePrint(calendarVariableName));

=== 2 ===
if (window.matchMedia) {
let mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener((mql) => {
if (mql.matches) {
calendarBeforePrint(calendar1);
}
})
}

Actual results:

As asked on stackoverflow:
https://stackoverflow.com/questions/78861327/javascript-firefox-print-events-not-working?noredirect=1#comment139040097_78861327

=== 1 ===
using this is not working as intended:

window.addEventListener("beforeprint", () => calendarBeforePrint(calendarVariableName));
window.addEventListener("afterprint", () => calendarBeforePrint(calendarVariableName));

In Chromium browsers:
when print preview opens: beforeprint is triggered
when print preview closes: afterprint is triggered

In Firefox:
when print preview opens: beforeprint is triggered AND afterprint is triggered
when print preview closes: (nothing is triggered)

=== 2 ===
Catching the change of orientation (portrait or landscape) works in Chromium browsers, but not in Firefox:

if (window.matchMedia) {
let mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener((mql) => {
if (mql.matches) {
calendarBeforePrint(calendar1);
}
})
}

Tested on Firefox 129.0 64bit.

Expected results:

  1. Shoud fire afterprint event after closing print preview.
  2. should fire event for changing portrait/landscape mode

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

Component: Untriaged → DOM: UI Events & Focus Handling
Product: Firefox → Core

From previous bugs, I see that our printing flow differs from what the spec expects. Is the behavior claimed here intentional?

Flags: needinfo?(emilio)

The spec doesn't really say anything about this? Our printing approach is completely different to other browsers. We have bug 1663290 to track the timing of the afterprint event. Still, changing print settings won't trigger a re-clone of the document.

Status: UNCONFIRMED → RESOLVED
Closed: 1 year ago
Duplicate of bug: 1663290
Flags: needinfo?(emilio)
Resolution: --- → DUPLICATE

I not really can follow you, but to add more context:
=== 1 ===
Here is the afterprint event defined:
https://developer.mozilla.org/en-US/docs/Web/API/Window/afterprint_event
and was reported here:
https://bugzilla.mozilla.org/show_bug.cgi?id=1685011

=== 2 ===
For Firefox, I have not found any information about catching the event for switching between portrait and landscape mode in print preview.

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