Open Bug 1762800 Opened 4 years ago Updated 1 month ago

WebExtension code should take into account that adoptTab can abort

Categories

(WebExtensions :: Frontend, defect, P3)

defect

Tracking

(Not tracked)

ASSIGNED

People

(Reporter: Oriol, Assigned: Oriol)

References

(Depends on 3 open bugs, Blocks 1 open bug)

Details

Inspect a WebExtension and run:

var events = [];
browser.tabs.onDetached.addListener((...args) => {
  events.push(["onDetached", ...args]);
});
browser.tabs.onAttached.addListener((...args) => {
  events.push(["onAttached", ...args]);
});
browser.tabs.onRemoved.addListener((...args) => {
  events.push(["onRemoved", ...args]);
});
browser.tabs.onCreated.addListener((...args) => {
  events.push(["onCreated", ...args]);
});

Then, open the browser console and run:

gBrowser.addTab("about:preferences", {
  triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
  createLazyBrowser: true,
  allowInheritPrincipal: true,
  index: 0,
});

Back in the WebExtension:

var [tab] = await browser.tabs.query({index: 0, currentWindow: true});
tab.id; // 239
var win = await browser.windows.create({state: "minimized"});
await browser.tabs.move(tab.id, {windowId: win.id, index: 0}); // Error: An unexpected error occurred
await browser.tabs.move(tab.id, {windowId: win.id, index: 0}); // Error: Invalid tab ID: 239
await browser.tabs.get(tab.id); // Error: Invalid tab ID: 239
(await browser.tabs.query({index: 0, currentWindow: true}))[0].id; // 239
events; /* [
  ["onCreated", {id: 239, index: 0, windowId: 1, url: "about:preferences", ...}],
  ["onCreated", {id: 240, index: 0, windowId: 61, url: "about:blank", ...}],
  ["onDetached", 239, {oldWindowId: 1, oldPosition: 0}],
  ["onAttached", 239, {newWindowId: 61, newPosition: 0}],
  ["onRemoved", 239, {windowId: 61, isWindowClosing: false}],
] */

What's happening here is that adoptTab aborts due to bug bug 1758307. And this breaks WebExtensions:

Thank you Oriol, that part about adopting has always been messy. Since you already investigated, do you maybe want to take this?

Severity: -- → S3
Priority: -- → P3
Depends on: 1763911
Depends on: 1763914
Depends on: 1763916
You need to log in before you can comment on or make changes to this bug.