window.open() Popup is blocked when called from a user interaction event
Categories
(Core :: DOM: Events, defect)
Tracking
()
People
(Reporter: NadeemAfana, Unassigned)
References
(Depends on 1 open bug)
Details
Attachments
(1 file, 2 obsolete files)
1.03 KB,
text/html
|
Details |
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0
Steps to reproduce:
See the attachment html file for a demo.
-
Create a button in an html page with an async "click" event handler.
-
In the button "click" event handler, create a message listener using window.addEventListener( "message",..) and wait for one message to come using a promise as the following
// Wait for an incoming message
await new Promise((res, rej) => {
// Wait for a message
window.addEventListener(
"message",
function handler(event) {
console.log('received message', event);
window.removeEventListener("message", handler, false);
res();
},
false,
);
}); -
Send a message to unblock the listener. This could inside or outside the click event handler: setTimeout(window.postMessage('message'), 100);
-
Call window.open() inside the handler as soon as a message is received
Actual results:
The pop-up is blocked and I see the Firefox warning "Firefox prevented this site from opening a pop-up window."
Technical Notes:
It seems the PopupBlocker component is using the "message" event, which is a disallowed event instead of considering the click event though the window.open was not called from the message handler itself.
Expected results:
The pop-up is opened and without a warning.
Comment 1•1 year ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::DOM: Events' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•1 year ago
|
||
Oliver, would you want to investigate this a bit and see how this relates with the pop-up user activation model work you're working on?
Comment 3•1 year ago
|
||
This looks like it would be fixed by the popup blocker moving to using the user activation model, I'm guessing the reason this doesn't currently work is the popup blocker is quite tied to specific events unlike the user activation model which should allow 1 popup if there's an active (last 3s) user activation (eg click).
Updated•1 year ago
|
Updated•1 year ago
|
Updated•9 months ago
|
Comment 6•8 months ago
|
||
Comment 7•8 months ago
|
||
Updated•8 months ago
|
Updated•7 months ago
|
Comment 8•7 months ago
|
||
(Perhaps we could consider falling back to check user activation when popup state is openBlocked
, see bug 1894244 comment 2, which could also fix this, too)
Description
•