Closed Bug 1681457 Opened 4 years ago Closed 22 days ago

Window.Close() not allowing closing tab opened as new window by script from another Page

Categories

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

Firefox 83
defect

Tracking

()

RESOLVED FIXED
128 Branch
Tracking Status
firefox-esr78 --- wontfix
firefox84 --- wontfix
firefox85 --- wontfix
firefox86 --- wontfix
firefox128 --- fixed

People

(Reporter: manish.iit06, Assigned: nika)

References

Details

Attachments

(1 file)

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

Steps to reproduce:

Open new tab by clicking a link on Page.
New Page has form to be submitted.
Once the form is posted to server i want to close this new tab.

Actual results:

I get the error "Scripts may not close windows that were not opened by script".

Expected results:

I should be able to close the tab somehow.

Summary: Opening new tab in new window by script will not close the window reloaded again by posting form → Window.Close() not allow closing tab opened new window by script

(In reply to manish.iit06 from comment #0)

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

Steps to reproduce:

Open new tab by clicking a link on Page.
New Page has form to be submitted.
Once the form is posted to server i want to close this new tab.

Actual results:

I get the error "Scripts may not close windows that were not opened by script".

Expected results:

I should be able to close the tab somehow.

Summary: Window.Close() not allow closing tab opened new window by script → Window.Close() not allowing closing tab opened as new window by script from another Page
Component: Untriaged → DOM: Navigation
Product: Firefox → Core

A (minimal) testcase is needed here, or exact steps to reproduce in some other way.

Flags: needinfo?(manish.iit06)

Steps to reproduce:

(1) Open Webpage in Firefox Browser.
(2) Click a link(anchor <a href="abc.com" target="_blank"></a>) on Page which open a new Page in new tab.
(3)The new tab has form to submit, fill the form and Submit to server.
(4) Server returns the confirmation Page with CloseButton to close this tab(so that user can return back on original Page).
(5) This CloseButton on click event is bind to method with command window.Close()
Now if i click the CloseButton window.close() method is executed and
I get the error "Scripts may not close windows that were not opened by script".

The same thing works fine in other browsers.

Flags: needinfo?(manish.iit06)

This is because targeted links now default to noopener. If you add rel="opener", it should work.

Yes true, Its working now ...Big thanks :)
I am just wondering why the same thing not applicable to Chrome.

Anne, do we want to fix this? Should pages opened with rel="noopener" be allowed to close themselves with script? IIUC, Nika says the spec is ambiguous and Chrome allows this.

Flags: needinfo?(annevk)

Yeah, so https://html.spec.whatwg.org/#script-closable talks about documents in the session history, but I suspect it wants to talk about entries or some such instead as documents can get collected. And it has other issues too, as discussed and linked from https://github.com/whatwg/html/issues/1866. I think we should make this work as having people add rel=opener everywhere would be bad and there is not a downside as far as I can tell.

Flags: needinfo?(annevk)

(In reply to Anne (:annevk) from comment #7)

I think we should make this work as having people add rel=opener everywhere would be bad and there is not a downside as far as I can tell.

needinfo Nika to share the steps to fix. Should be easy to fix.

Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(nika)
Priority: -- → P2

I believe bug 1353466 meant that pop-up windows are able to close themselves if they are the only history entry, but it seems like this perhaps isn't the case for situations like the one described in the bug still as there was a navigation.

The obvious thing to do here would be to mark BrowsingContexts created due to noopener window.open calls from script to be marked as HadOriginalOpener(). It looks like most code which checks this flag wouldn't be negatively impacted by this, however https://searchfox.org/mozilla-central/rev/3759e3792f8426e1f75e40c1d6566569b22a7dc1/dom/ipc/ProcessIsolation.cpp#747 would now no longer allow windows created in this way to enter the BFCache, which is probably undesirable.

In addition, doing this change would change whether these contexts are considered "auxiliary" (e.g. https://searchfox.org/mozilla-central/rev/3759e3792f8426e1f75e40c1d6566569b22a7dc1/dom/clients/manager/ClientSource.cpp#296). I believe that windows opened with noopener should not be considered auxiliary, though I'd need to double-check to spec to be certain.

The easiest approach therefore is probably to introduce a new flag which can be set by the window.open code specifically for this which is distinct.

Assignee: nobody → nika
Flags: needinfo?(nika)
Pushed by nlayzell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1034029ae9ed
Allow non-auxiliary BrowsingContexts created by script to close themselves, r=smaug
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/46570 for changes under testing/web-platform/tests

Backed out for causing failures on test_window_close.html

Backout link

Push with failures

Failure log

Flags: needinfo?(nika)
Upstream PR was closed without merging
See Also: → 1895083
Flags: needinfo?(nika)
Pushed by nlayzell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/f42a7bd094a9
Allow non-auxiliary BrowsingContexts created by script to close themselves, r=smaug
Status: NEW → RESOLVED
Closed: 22 days ago
Resolution: --- → FIXED
Target Milestone: --- → 128 Branch
Upstream PR merged by moz-wptsync-bot
Duplicate of this bug: 1895083
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: