Open Bug 2036556 Opened 1 month ago Updated 19 days ago

scripting.executeScript on discarded tab: can't access property "currentWindowGlobal", bc is null

Categories

(WebExtensions :: General, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: kernp25, Unassigned)

References

Details

Attachments

(1 file)

Attached image firefox_uV1ZOWUhsL.png

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

Steps to reproduce:

Need to find out.

Actual results:

The error in the browser console.

Hello,

This appears to be a race condition in the internal WebExtension API, but I haven't been able to reproduce it.
I’ve tried using a test extension that rapidly opens and closes tabs in the hope that this will trigger the issue, but with no success, so far.

Would you mind letting me know what extensions you currently have installed and if the issue occurs more frequently on a specific website?

Flags: needinfo?(kernp25)

Coincidentally I saw this error yesterday while working on unit tests for bug 1653876.

This can happen when browser.scripting.executeScript is called for a discarded tab:

tab = await browser.tabs.create({ discarded: true, url: "https://example.com/" })
await browser.scripting.executeScript({ target: { tabId: tab.id }, func: () => {} });

the above rejects with "An unexpected error occurred"

And the global Browser Console shows:

can't access property "currentWindowGlobal", bc is null ext-tabs-base.js:745:17
    visit chrome://extensions/content/parent/ext-tabs-base.js:745
    queryContent chrome://extensions/content/parent/ext-tabs-base.js:757
    execute chrome://extensions/content/parent/ext-scripting.js:118
    executeScriptInternal chrome://extensions/content/parent/ext-scripting.js:193
    result resource://gre/modules/ExtensionParent.sys.mjs:1221
    withCallContextData resource://gre/modules/ExtensionParent.sys.mjs:664
    result resource://gre/modules/ExtensionParent.sys.mjs:1220
    withPendingBrowser resource://gre/modules/ExtensionParent.sys.mjs:674
    result resource://gre/modules/ExtensionParent.sys.mjs:1219
    callAndLog resource://gre/modules/ExtensionParent.sys.mjs:1170
    recvAPICall resource://gre/modules/ExtensionParent.sys.mjs:1218

The queryContent method is generic and also shared by tabs.detectLanguage, tabs.executeScript, tabs.insertCSS, tabs.removeCSS and scripting.executeScript.

However, due to bug 1653876 this code path is not reached for all other tabs methods.

The scripting.executeScript method can reach this because it does not wait for tab readiness (bug 1813585).

The implementation needs to be refactored to support documentId (bug 1891478), so perhaps this will be fixed as part of the same effort.

Severity: -- → S4
Status: UNCONFIRMED → NEW
Component: Frontend → General
Ever confirmed: true
Flags: needinfo?(kernp25)
Priority: -- → P3
See Also: → 1653876, 1813585, 1891478
Summary: can't access property "currentWindowGlobal", bc is null → scripting.executeScript on discarded tab: can't access property "currentWindowGlobal", bc is null
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: