Open Bug 1900220 Opened 2 years ago Updated 2 years ago

NS_ERROR_ILLEGAL_VALUE in nsIDOMWindowUtils.addSheet when running insertCSS from webextension

Categories

(WebExtensions :: General, defect, P5)

Firefox 126
All
Android
defect

Tracking

(firefox126 affected, firefox127 affected, firefox128 affected)

Tracking Status
firefox126 --- affected
firefox127 --- affected
firefox128 --- affected

People

(Reporter: top.car8902, Unassigned)

Details

Steps to reproduce:

Firefox 126 on both my Android phone and my Mac. Android phone is a Pixel 6 running Android 14.

  1. Download my extension's source code from Github at this commit: https://github.com/RickyRomero/shut-up-webextension/tree/d4ddefcd3d66e771a70cf037bb596bc33340586b
  2. Delete src/manifest.json
  3. Rename src/manifest.ffx.json to src/manifest.json
  4. Load the extension on an Android phone using web-ext from the src folder
  5. Connect debugger to Android phone via about:debugging
  6. Go to the phone's device page in the debugging UI and open Multiprocess Toolbox
  7. Enable Multiprocess (Slower)
  8. Turn on requested permissions if necessary from extension's options page
  9. Open https://old.reddit.com/r/aww/comments/1d5sdin/my_17_yr_old_blind_and_deaf_shiba_loves_the/ on the phone in a new tab

Actual results:

Extension times out after a few seconds trying to run insertCSS from blocker.js. The multiprocess toolbox throws this error:

[Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMWindowUtils.addSheet]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: resource://gre/modules/ExtensionCommon.sys.mjs :: runSafeSyncWithoutClone :: line 61" data: no] ExtensionCommon.sys.mjs:61:12
runSafeSyncWithoutClone resource://gre/modules/ExtensionCommon.sys.mjs:61
cssPromise resource://gre/modules/ExtensionContent.sys.mjs:531
InterpretGeneratorResume self-hosted:1412
AsyncFunctionNext self-hosted:799
(Async: async)
inject resource://gre/modules/ExtensionContent.sys.mjs:527
injectInto resource://gre/modules/ExtensionContent.sys.mjs:458
AsyncFunctionNext self-hosted:799
(Async: async)
executeInWin resource://gre/modules/ExtensionContent.sys.mjs:1241
map self-hosted:175
handleActorExecute resource://gre/modules/ExtensionContent.sys.mjs:1246
InterpretGeneratorResume self-hosted:1412
AsyncFunctionNext self-hosted:799
(Async: async)
receiveMessage resource://gre/modules/ExtensionContent.sys.mjs:1291

Expected results:

One of two things should occur:

  1. If successful, the CSS should be inserted into the page and comments should be hidden
  2. If an error occurs, the insertCSS promise is supposed to settle in the webextension's background script by rejecting, not hang indefinitely while nothing happens

insertCSS should not throw an error in this specific case because the same CSS works fine on Firefox desktop.

The error is occur because of https://searchfox.org/mozilla-central/rev/42bbfc3f84343f532259dfd73067dcc1de0a8a32/dom/base/Document.cpp#7536

Is the const baseTimeout = 50 // ms too small ? It might cause that the first insertCss is just in the middle of process and then the second one would be executed because of timeout and the second one would fail ?

@jackyzy823
I've simplified my test case to only the code that's essential to how my extension works. Please try again with the new branch:
https://github.com/RickyRomero/shut-up-webextension/tree/fenix-css-bug

This will still reproduce the NS_ERROR_ILLEGAL_VALUE bug on the page I mentioned, but it's simpler code and it doesn't include the timeout you were curious about. I am unsure if the promise will hang in this case.

(The timeout is a workaround for another Firefox bug which is also present on Fenix 126. Basically, on heavy websites, sometimes insertCSS/removeCSS promises don't resolve or reject and just hang open, so I just have to retry over and over until I finally get one of the promises to settle.)

Sorry for the misleading.

I think the problem is that at the same time , there's only one sheet with the same name could be injected in same document?

So if you've already injected "moz-extension://<extid>/resources/shutup.css", you should remove it before re-inject it.
Even with css string , it will use data URL format like "data:text/css;extension=style;charset=utf-8,xxxxx" to check duplication.

I'm not sure which is the correct behavior (because it is an undefined behavior). Should we 1) Replace the previous injected one or 2) throw an Error if already exists or 3) silently return OK even if exists?

A possible workaround is to removeCSS before every injectCSS.

Component: WebExtensions → General
Product: Fenix → WebExtensions

(In reply to jackyzy823 from comment #3)

A possible workaround is to removeCSS before every injectCSS.

For what it’s worth, when I submitted this bug, that’s what my code was doing. I removed that in my simplified test case because the same error occurred regardless.

Hello,

I reproduced the error on the latest Nightly 128.0a1, Beta 127.0b9 and Release 126.0.1 for Android on an Oppo Reno 6 5G running Android 13.

The error was not always displayed as soon as the reddit page was accessed, but it did get logged to console after a page refresh, without fail. However, the comments were hidden each time, so the results of inserting the CSS are as expected.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(rob)

(In reply to Ricky Romero from comment #0)

Actual results:

Extension times out after a few seconds trying to run insertCSS from blocker.js.

Can you still reproduce this? I think that you were affected by bug 1900222, which I fixed.

The multiprocess toolbox throws this error:

[Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMWindowUtils.addSheet]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: resource://gre/modules/ExtensionCommon.sys.mjs :: runSafeSyncWithoutClone :: line 61"

This error is only reported internally. It happens when the sheet was already inserted before.

Flags: needinfo?(rob) → needinfo?(top.car8902)

(In reply to Rob Wu [:robwu] from comment #7)

(In reply to Ricky Romero from comment #0)

Actual results:

Extension times out after a few seconds trying to run insertCSS from blocker.js.

Can you still reproduce this? I think that you were affected by bug 1900222, which I fixed.

Judging by your comment at https://bugzilla.mozilla.org/show_bug.cgi?id=1900222#c23, I think that the fix indeed addressed this part of your report.

That leaves only the following part. This is just "logspam" indicating an actual issue in the extension, but doesn't result in broken behavior. In particular, the insertCSS promise will resolve.

The multiprocess toolbox throws this error:

[Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMWindowUtils.addSheet]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: resource://gre/modules/ExtensionCommon.sys.mjs :: runSafeSyncWithoutClone :: line 61"

This error is only reported internally. It happens when the sheet was already inserted before.

Severity: -- → S4
Flags: needinfo?(top.car8902)
Priority: -- → P5

Hi @robwu,

You are correct that this bug and #1900222 are closely related – I’d filed them for the same reasons. The performance characteristics affecting that bug were so drastically different on mobile, I figured other problems might be at play.

Long story short, I just tested on the mobile beta (128.0b9) and your fix worked there too! The only “issue” is the log spam, which doesn’t really affect me.

Really appreciate how thorough you are in addressing these issues. Thank you so much.

You need to log in before you can comment on or make changes to this bug.