JavaScript Firefox print events not working
Categories
(Core :: DOM: UI Events & Focus Handling, defect)
Tracking
()
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:
- Shoud fire afterprint event after closing print preview.
- should fire event for changing portrait/landscape mode
Comment 1•1 year ago
|
||
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.
Comment 2•1 year ago
|
||
From previous bugs, I see that our printing flow differs from what the spec expects. Is the behavior claimed here intentional?
Comment 3•1 year ago
|
||
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.
| Reporter | ||
Comment 4•1 year ago
|
||
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.
Description
•