Cannot assign array to adoptedStyleSheets in extension content scripts
Categories
(WebExtensions :: General, defect, P3)
Tracking
(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
Comment 1•1 year ago
|
||
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.
Comment 2•1 year ago
|
||
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
Comment 3•1 year ago
|
||
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 !
A minimal reproduceable testcase has been added to attachments
Comment 6•1 year ago
|
||
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.
Updated•1 year ago
|
Comment 7•1 year ago
|
||
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.
Description
•