"TypeError: Argument 1 of PrecompiledScript.executeInGlobal is not an object." in ExtensionContent.jsm:354

NEW
Unassigned

Status

defect
P5
normal
2 years ago
Last year

People

(Reporter: robwu, Unassigned)

Tracking

57 Branch

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

This happened in Firefox Nightly 58.0a1 build ID 20170926100259.

I reloaded an extension whose manifest.json contains content_scripts at document_idle, while a page was being loaded. This resulted in the following error being printed TWICE in the console:
"TypeError: Argument 1 of PrecompiledScript.executeInGlobal is not an object."
at this line: https://searchfox.org/mozilla-central/rev/3dbb47302e114219c53e99ebaf50c5cb727358ab/toolkit/components/extensions/ExtensionContent.jsm#354

I tried to reproduce afterwards, but am not able to, because this seems like a race condition, where the context has been closed (and nulled context.cloneScope, hence the error).

I believe that the script injection logic needs to check whether the context is still valid in multiple places (and return if the context is invalid):

1. In injectInto, after every await statement (lines 267, 274-277)
   (OR at the top of the inject function (line 294))

2. After every script.executeInGlobal(context.cloneScope) call (line 354), because the script could destroy the context.

The check could be something like
if (!context.contentWindow) return;
or
if (!context.cloneScope) return;
or
if (context.unloaded) return;
I managed to consistently reproduce this bug.
I was experimenting with webRequest & StreamFilter (bug 1255894) when this happened, so maybe the webRequest part is not really relevant.

1. Load attached extension.
2. Click on the extension button to open an example.com URL that is intercepted by a webRequest listener (and a stream filter is attached).
3. Reload the page.
4. Reload the page.
5. Reload the page.

After the third reload, all subsequent reloads will emit the reported error.

This is the console after running the above steps:
streamFilter.ondata  background.js:6:9
streamFilter.onstop  background.js:10:9
streamFilter.ondata  background.js:6:9
streamFilter.onstop  background.js:10:9
streamFilter.ondata  background.js:6:9
"Ran content script at https://example.com/?suspendme. browser.runtime=[object Object]"  contentscript.js:1
streamFilter.ondata  background.js:6:9
streamFilter.onstop  background.js:10:9
streamFilter.ondata  background.js:6:9
TypeError: Argument 1 of PrecompiledScript.executeInGlobal is not an object.  ExtensionContent.jsm:354:18
Priority: -- → P5
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.