Open Bug 1928865 Opened 1 year ago Updated 3 months ago

Cannot assign array to adoptedStyleSheets in extension content scripts

Categories

(WebExtensions :: General, defect, P3)

Firefox 132
Unspecified
Windows 10
defect

Tracking

(firefox132 affected, firefox133 affected, firefox134 affected)

Tracking Status
firefox132 --- affected
firefox133 --- affected
firefox134 --- affected

People

(Reporter: squawgee, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

573 bytes, application/x-zip-compressed
Details

Steps to reproduce:

In a Firefox add-on content script attempt the following:

const sheet = new CSSStyleSheet()
sheet.insertRule(...)
document.adoptedStyleSheets = [sheet]

Actual results:

Error: Accessing from Xray wrapper is not supported.

Expected results:

adoptedStyleSheets working according to spec.
https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptedStyleSheets

Related issue:
https://bugzilla.mozilla.org/show_bug.cgi?id=1766909

OS: Unspecified → Windows 10
Summary: Regression of adoptedStyleSheets Xray expando breaking extensions → Regression of adoptedStyleSheets Xray expando breaking add-ons

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

The bug claims that this is a regression, but is it? I think that it always worked (or rather: not worked) like this.

This looks like a valid bug report (related to bug 1751346), and I'd like to change the title to something like: "Cannot assign array to adoptedStyleSheets in extension content scripts"

The test added in bug 1766909 also shows that this is currently the expected behavior: https://searchfox.org/mozilla-central/rev/964b8aa226c68bbf83c9ffc38984804734bb0de2/dom/bindings/test/test_observablearray.html#538-540

Hello,

Would you be so kind as to attach a test extension matching the characteristics from Comment 0 so I can attempt to reproduce this issue?

Thank you !

Flags: needinfo?(squawgee)

Sure, I'll see if I have a moment maybe by end of today.

Flags: needinfo?(squawgee)
Summary: Regression of adoptedStyleSheets Xray expando breaking add-ons → Cannot assign array to adoptedStyleSheets in extension content scripts

A minimal reproduceable testcase has been added to attachments

Thank you for the test extension @Xzensi !

I reproduced the issue on the latest Nightly (134.0a1/20241107212807), Beta (133.0b5/20241106091549) and Release (132.0.1/20241103194048) under Windows 10 and Ubuntu 22.04 LTS.

As soon as I access https://example.com/, the browser console logs the mentioned error.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Severity: -- → S3
Component: Untriaged → General
Depends on: 1751346
Priority: -- → P3

There are already multiple bugs related to adoptedStylesheets not working (bug 1817675, bug 1770592). I did not close this bug as a duplicate of the others, because in theory the other bugs could be fixed by changing the behavior of the value of adoptedStylesheets.

To fix this specific bug, the property descriptor (setter) needs to somehow unwrap the Xrays of the wrapper. It could potentially special-case the behavior, by limiting the types of the values, so that this property descriptor cannot be misused to unwrap Xrays of arbitrary objects.

Related issue on my extension TypeError: document.adoptedStyleSheets.push is not a function when trying to add stylesheet to the root document from within a shadow root element

Add-on: https://addons.mozilla.org/en-US/firefox/addon/amgiflol/
Version: 0.3.0

Reproduction:
Install the extension, and load any web page. The exception will block instantization of the extension.

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

Attachment

General

Creator:
Created:
Updated:
Size: