Open Bug 1863217 Opened 11 months ago Updated 3 months ago

window.open() Popup is blocked when called from a user interaction event

Categories

(Core :: DOM: Events, defect)

Firefox 119
defect

Tracking

()

People

(Reporter: NadeemAfana, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(1 file, 2 obsolete files)

Attached file page.html

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.

  1. Create a button in an html page with an async "click" event handler.

  2. 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,
    );
    });

  3. Send a message to unblock the listener. This could inside or outside the click event handler: setTimeout(window.postMessage('message'), 100);

  4. 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.

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.

Component: Untriaged → DOM: Events
Product: Firefox → Core

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?

Flags: needinfo?(omedhurst)

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).

Flags: needinfo?(omedhurst)
Status: UNCONFIRMED → NEW
Depends on: 1656444
Ever confirmed: true
Severity: -- → S3
Attachment #9386299 - Attachment is obsolete: true

This is the same root cause as bug 1739655.

See Also: → 1739655
Assignee: nobody → echen
See Also: → 1894244
Attachment #9391575 - Attachment is obsolete: true

(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)

(Let's wait for bug 1894244 and revisit this)

Assignee: echen → nobody
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: