Closed Bug 1762249 Opened 4 years ago Closed 4 months ago

tabs.create() fails when it is called with "openerTabId" for a discarded tab

Categories

(WebExtensions :: Compatibility, defect, P3)

defect

Tracking

(firefox148 fixed)

RESOLVED FIXED
148 Branch
Tracking Status
firefox148 --- fixed

People

(Reporter: yuki, Assigned: yuki)

Details

Attachments

(2 files)

browser.tabs.create() throws an error unexpectedly when openerTabId is an ID of a discarded tab.

Original report: https://github.com/piroor/treestyletab/issues/3099

Steps to reproduce

  1. Open two or more tabs.
  2. Discard one of tabs.
  3. Call browser.tabs.create({ openerTabId: <the ID of a discarded tab> }).

Expected result

A new tab is opened successfully.

Actual result

No tab is created. If you catch errors of the API call, you get an error with a message "Error: An unexpected error occurred".

Environment

  • Windows 10 21H2
  • Nightly 100.0a1 build ID: 20220329204247
  • Firefox 98.0.2 build ID: 20220322144853

Here is a testcase addon. You can confirm that the result is different between Firefox and Google Chrome.

On Firefox:

  1. Go to about:debugging.
  2. Click "This Firefox" (or "This Nightly").
  3. Click "Load Temporary Add-on...".
  4. Choose the testcase XPI.
    • Expected result:
      • Two tabs https://example.com/?parent and https://example.com/?child are opened.
    • Actual result:
      • Only one tab https://example.com/?parent is opened.
      • If you open the debugger for the testcase addon, an error "Error: An unexpected error occurred" is reported.

On Google Chrome (I've used Chrome 99.0.4844.84):

  1. Go to chrome://extensions/.
  2. Activate developer mode.
  3. Click "Load unpacked extension".
  4. Choose the directory extracted the testcase XPI.
    • Result:
      • Two tabs https://example.com/?parent and https://example.com/?child are opened.

Firefox gets tracked tabs based on the given openerTabId with:
https://searchfox.org/mozilla-central/rev/766773ca7e3495a3f1ba365f47dffefdea29e3ee/browser/components/extensions/parent/ext-tabs.js#732
https://searchfox.org/mozilla-central/rev/766773ca7e3495a3f1ba365f47dffefdea29e3ee/browser/components/extensions/parent/ext-tabs.js#898
Something further operation looks to raise the "Error: An unexpected error occurred" error, but I've not found which code does that yet.

I've got that the error comes from https://searchfox.org/mozilla-central/rev/625c3d0c8ae46502aed83f33bd530cb93e926e9f/browser/base/content/tabbrowser.js#2837 , the raw error is: CanonicalBrowsingContext.setCrossGroupOpener: Argument 1 is not an object.

Just skipping CanonicalBrowsingContext.setCrossGroupOpener() for null openerBrowser.browsingContext looks reasonable for me, because the only one code using the returned value of GetCrossGroupOpenerId() looks to be here and the function is designed to do nothing when the opener tab is already discarded. Is it a correct approach?

Flags: needinfo?(nika)

Skipping that call if the opener browser is not available seems very reasonable, yes.

Flags: needinfo?(nika)
Assignee: nobody → yuki
Status: NEW → ASSIGNED

Thanks!

Severity: -- → S3
Priority: -- → P3

I apologize my long silence about the patch. I've rewrite it based on the latest mozilla-central, with fixes commented by the reviewer.

Thanks for the patch, Piro!

I just wanted to note that this bug seems to cause a data loss issue with Tab Session Manager, when used with Tree Style Tab / Sidebery support. When restoring a session, in some conditions a tab will fail to open, without user notification, causing subtle corruption of the session:

Tab is not restored if it's a Tree Style Tab child tab, and was the active tab when saved. · Issue #1548 · sienori/Tab-Session-Manager

I tried the above testcase xpi with Developer Edition 147, and the console error message is the same as with Tab Session Manager:

DOMException: CanonicalBrowsingContext.crossGroupOpener setter: Can't set crossGroupOpener to null

The patch has been reviewed and accepted. I have no authority so could anyone check-in it?

Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 148 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: