Closed Bug 1643450 Opened 5 years ago Closed 4 years ago

Since Firefox 72, target="_blank" and window.close() do no longer work together

Categories

(Core :: DOM: Navigation, defect, P3)

72 Branch
defect

Tracking

()

RESOLVED FIXED
87 Branch
Tracking Status
firefox-esr78 --- wontfix
firefox81 --- wontfix
firefox82 --- wontfix
firefox83 --- wontfix
firefox87 --- fixed

People

(Reporter: maximilian.schlederer, Assigned: nika)

References

Details

Attachments

(3 files)

Attached file testcase.html

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0

Steps to reproduce:

Assume you create a new window (pop-up) using javascript and have its content be something like this:

<html>
<body>
<form action="some_action.php" target="_blank"> 
    ... some form fields ... 

    <button onclick="window.close()">
        submit in new tab & close pop-up
    </button>
</form> 

<a href="some_page.php" target="_blank" onclick="window.close()">
    open link in new tab & close pop-up 
</a>
</body>
</html>

I have also attached a test case (html).

Actual results:

If you click the "submit in new tab & close pop-up" button or the "open link in new tab & close pop-up" link this happens:

  1. Firefox only opens an empty tab, i.e. the submission of the form (the opening of the link) fails
  2. The pop-up closes itself

Expected results:

If you click the button "submit in new tab & close pop-up" the following should happen:

  1. Firefox submits the form in a new tab (because target="_blank" is set in the <form>)
  2. The pop-up closes itself (because onclick="window.close()" is set)

And if you click the link "open link in new tab & close pop-up" the following should happen:

  1. Firefox opens the link in a new tab (because target="_blank" is set in the <a>)
  2. The pop-up closes itself (because onclick="window.close()" is set)

This clearly seems to be a bug, right? Is this a known problem? I tested it with older versions and the problem apparently was introduced relatively recently with Firefox 72. More precisely, the form submission bug was introduced with Firefox 72 Beta 1 and the link opening bug was introduced with Firefox 72 Beta 7.

In Chrome and Internet Explorer both cases work as expected.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core

When a tab closes, pending network tasks may be canceled. Try a delay on closing the tab:

<button onclick="window.setTimeout(function(){window.close();}, 250);">

Example:

https://www.jeffersonscher.com/res/closeme.html

Yes setting a short timeout is the obvious workaround. However I want to emphasize that closing the window here should not cancel any "pending network tasks" since those belong (should belong) to the newly opened tab and not to the one which is closed.

Component: DOM: Core & HTML → DOM: Navigation
See Also: → 1316857

This should be working now on Nightly (bug 1353466).
Reporter, could you try Nightly and reopen this if this doesn't work.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Flags: needinfo?(maximilian.schlederer)
Resolution: --- → FIXED
Status: RESOLVED → UNCONFIRMED
Flags: needinfo?(maximilian.schlederer)
Resolution: FIXED → ---

(In reply to Olli Pettay [:smaug] from comment #4)

This should be working now on Nightly (bug 1353466).
Reporter, could you try Nightly and reopen this if this doesn't work.

It doesn't work. Instead the problem got worse: Apart from the form failing to submit / the link failing to open, now not even a new tab is created.

The severity field is not set for this bug.
:smaug, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(bugs)

I can reproduce this problem in Firefox 83 Nightly with the test case. In Chrome, it opens a new tab. In Firefox, it doesn't open a new tab.

Assign to Nika.

P3/S3

Assignee: nobody → nika
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3

This is being caused by a race between the close logic going through and the window.open logic. When the link is clicked, first the onclick listener is called, which will call window.close(), and then the new pop-up window is created due to clicking on a <a target=_blank> link.

  • The close call will immediately dispatch DOMWindowClose, which is handled by content JS, and starts the window close process.
    • A message will be sent from content to parent to start the close,
    • This message will end up spinning the parent process event loop at least once before actually closing the window (which will mark the content context as discarded)
  • The pop-up creation will send an a CreateWindowInDifferentProcess message to the parent process.

The issue here is that it is possible for the DOMWindowClose message from content to parent to be fully processed, including the full spin of the event loop, before the CreateWindowInDifferentProcess message arrives. This means that the parent process already considers the window closed when the message arrives. The window opening request is then cancelled due to the parent context already being discarded, and we encounter this bug.

The easiest fix here is probably to relax the check in CreateWindowInDifferentProcess to allow creating a pop-up window if the parent window is partially, but not fully, discarded.

Pushed by nlayzell@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/5eacf74bc04f Allow creating windows from closing tabs, r=kmag
Attachment #9194024 - Attachment description: Bug 1643450 - Allow creating windows from closing tabs, → Bug 1643450 - Part 1: Allow creating windows from closing tabs,
Flags: needinfo?(nika)
Pushed by nlayzell@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/baa6b71bfaef Part 1: Allow creating windows from closing tabs, r=kmag https://hg.mozilla.org/integration/autoland/rev/f82872c9ec11 Part 2: Disable test on android due to aggressive background tab freezing, r=kmag
Status: NEW → RESOLVED
Closed: 5 years ago4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 87 Branch
Flags: qe-verify+
Flags: needinfo?(bugs)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: