Closed Bug 1675940 Opened 4 years ago Closed 4 years ago

window.close() does not work from inside the window (regardless of allowScriptsToClose in browser.windows.create())

Categories

(Thunderbird :: Add-Ons: Extensions API, defect)

defect

Tracking

(thunderbird_esr78 fixed, thunderbird84 fixed)

RESOLVED FIXED
85 Branch
Tracking Status
thunderbird_esr78 --- fixed
thunderbird84 --- fixed

People

(Reporter: lieser2, Assigned: TbSync)

Details

Attachments

(1 file, 2 obsolete files)

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

Steps to reproduce:

  1. Open an extension window with
browser.windows.create({url: "./popup.html)", type: "popup", allowScriptsToClose: true});
  1. In a script (type module) loaded inside popup.html, call window.close()

Actual results:

Warning that scripts can only close windows that they open.

Expected results:

Window should close itself, as the allowScriptsToClose was set to true (which should already be the case for extensions windows anyway according to https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/windows/create).

Note that the url for some reasons is not set for the tab if you e.g. call await browser.windows.getAll({populate: true}). Not sure if this is related.

As a workaround one can use browser.windows.remove() (see e.g. example at https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/windows/remove#Examples).

The ugly think with the workaround is if you close the current window that way, the error console gets polluted with the following error message:

 Error: CallResult for closed conduit dkim_verifier@pl.2993: ({childId:"dkim_verifier@pl.2993", callId:2996, path:"windows.remove", result:{}}) ConduitsChild.jsm:167:13
    receiveMessage resource://gre/modules/ConduitsChild.jsm:167
Summary: window.close → window.close() does not work from inside the window (regardless of allowScriptsToClose in browser.windows.create())
Assignee: nobody → john
Status: UNCONFIRMED → NEW
Ever confirmed: true

First attempt did not work.

The reason this works in TB79+ but not in TB78 is this change introduced in bug 1353466 (TB79):
https://searchfox.org/comm-central/source/mozilla/dom/base/nsGlobalWindowOuter.cpp#6261

[TB79+]
The added check for !IsOnlyTopLevelDocumentInSHistory seems to bypass the check for allowClose further down. That is why the value for allowScriptsToClose is ignored (setting it to false has no effect in TB79+).
Due to bug 1353466 FF79+ and TB79+ ignore allowScriptsToClose = false and allows all scripts in popup windows to close themselves.

[TB78]
TB78 never called windowUtils.allowScriptsToClose() like FF78 did, so scripts cannot close themselves for us
https://searchfox.org/comm-central/source/mozilla/toolkit/components/extensions/ext-browser-content.js#80

The provided patch attaches allowScriptsToClose to the arguments passed to extensionPopup.xhtml and calls windowUtils.allowScriptsToClose() for the content window if needed.

As long as the free pass introduced in bug 1353466 is not removed from TB79+, this patch has no effect. But it is needed for TB78.

Attached patch bug1675940.patch (obsolete) — Splinter Review
Attachment #9188928 - Flags: review?(geoff)
Status: NEW → ASSIGNED

Comment on attachment 9188928 [details] [diff] [review]
bug1675940.patch

Well done figuring this out!

This patch needs a better commit message, but apart from that is good to go.

Attachment #9188928 - Flags: review?(geoff) → review+
Attached patch bug1675940.patch (obsolete) — Splinter Review

Updated commit message.

Attachment #9188928 - Attachment is obsolete: true
Attached patch bug1675940.patchSplinter Review

update email

Attachment #9189102 - Attachment is obsolete: true
Target Milestone: --- → 85 Branch

For comm-central I could only check the fails in Windows 10 locally

Without the patch:
X1: no fail
X2: fail

With the patch
X1: no fail
X2: fail

I have no idea why X1 fails on comm-central, if I run the latest tip locally it does not fail for me.

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/e5f25cad7939
Honour allowScriptsToClose argument in windows.create API function. r=darktrojan

Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED

Comment on attachment 9189104 [details] [diff] [review]
bug1675940.patch

[Approval Request Comment]
User impact if declined:
windows API will not work as documented

Testing completed (on c-c, etc.):
On comm-esr78
https://treeherder.mozilla.org/jobs?repo=try-comm-central&revision=209ca90561fa01eb55c142712d5ce421fb950a0a

Risk to taking this patch (and alternatives if risky):
I hope not.

Attachment #9189104 - Flags: approval-comm-release?
Attachment #9189104 - Flags: approval-comm-beta?

Comment on attachment 9189104 [details] [diff] [review]
bug1675940.patch

[Triage Comment]
Approved for beta
Approved for esr78

Attachment #9189104 - Flags: approval-comm-release?
Attachment #9189104 - Flags: approval-comm-release+
Attachment #9189104 - Flags: approval-comm-beta?
Attachment #9189104 - Flags: approval-comm-beta+

Comment on attachment 9189104 [details] [diff] [review]
bug1675940.patch

[Approval Request Comment]
User impact if declined:
windows API will not work as documented

Testing completed (on c-c, etc.):
On comm-esr78
https://treeherder.mozilla.org/jobs?repo=try-comm-central&revision=209ca90561fa01eb55c142712d5ce421fb950a0a

Risk to taking this patch (and alternatives if risky):
I hope not.

Attachment #9189104 - Flags: approval-comm-esr78?

Comment on attachment 9189104 [details] [diff] [review]
bug1675940.patch

[Triage Comment]
Approved for esr78 (with correct flag)

Attachment #9189104 - Flags: approval-comm-release+
Attachment #9189104 - Flags: approval-comm-esr78?
Attachment #9189104 - Flags: approval-comm-esr78+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: