Window.Close() not allowing closing tab opened as new window by script from another Page
Categories
(Core :: DOM: Navigation, defect, P2)
Tracking
()
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.
Reporter | ||
Updated•4 years ago
|
Reporter | ||
Comment 1•4 years ago
|
||
(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.
Updated•4 years ago
|
Comment 2•4 years ago
|
||
A (minimal) testcase is needed here, or exact steps to reproduce in some other way.
Reporter | ||
Comment 3•4 years ago
|
||
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.
Comment 4•4 years ago
|
||
This is because targeted links now default to noopener
. If you add rel="opener"
, it should work.
Reporter | ||
Comment 5•4 years ago
|
||
Yes true, Its working now ...Big thanks :)
I am just wondering why the same thing not applicable to Chrome.
Comment 6•4 years ago
|
||
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.
Comment 7•4 years ago
|
||
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.
Comment 8•4 years ago
|
||
(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.
Assignee | ||
Comment 9•1 month ago
|
||
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 | ||
Comment 10•1 month ago
|
||
Comment 11•27 days ago
|
||
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
Comment 13•27 days ago
|
||
Backed out for causing failures on test_window_close.html
Upstream PR was closed without merging
Assignee | ||
Updated•23 days ago
|
Comment 15•23 days ago
|
||
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
Comment 16•22 days ago
|
||
bugherder |
Upstream PR merged by moz-wptsync-bot
Updated•19 days ago
|
Description
•