Open Bug 1403505 Opened 7 years ago Updated 10 months ago

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

Categories

(WebExtensions :: General, defect, P5)

57 Branch
defect

Tracking

(Not tracked)

People

(Reporter: robwu, Unassigned)

References

Details

Attachments

(1 file)

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

I experienced this bug as well. For me to reproduce the error, I have to click the popup button 5 seconds after extension has loaded. I can click it as many times as I want before 5 seconds and it doesn't raise the error, after 5 seconds if I click the button it will throw the error:
TypeError: PrecompiledScript.executeInGlobal: Argument 1 is not an object. ExtensionContent.jsm:567:25
However it doesn't seem to cause any problems with the function of the browser extension. I have to confirm this though, it looks fine. I'll report on any more info later.

See Also: → 1717641
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: