also I cant add elements using shadowRoot.innerHTML
wOxxOm
unread,
Jan 5, 2024, 5:57:48 AM1/5/24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions, Ruslan Zhunus
It may fail in these two cases:
`document.body` doesn't have a child node if your content script runs at `document_start` - the solution is to append to document.documentElement or wait for body to appear via Mutation Observer or inside a DOMContentLoaded listener.
the site is using trustedHTML policy, so since it wasn't special-cased for extensions you need to abide by the rules for web pages and either use textContent instead of innerHTML (for simple text) or construct DOM using createElement explicitly (there are many libraries to assist in that e.g. quick googling shows crel), which is a very good practice anyway to avoid XSS and other inherent problems of html.
If none of the above helps, you need to debug the problem in the built-in devtools debugger.
wOxxOm
unread,
Jan 5, 2024, 5:58:51 AM1/5/24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions, wOxxOm, Ruslan Zhunus
...correction: `document.body` is absent if your content script runs at `document_start`
Ruslan Zhunus
unread,
Jan 5, 2024, 6:16:29 AM1/5/24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions, wOxxOm, Ruslan Zhunus
I have also tried using this code, but it did not work. my content script is running at 'document_idle'
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions, Ruslan Zhunus, wOxxOm
Since this exact code works in other extensions, there must be something else in the other parts of the script. Debug it in devtools or show the complete code here along with manifest.json so someone else could have a look. Maybe your content script doesn't run at all due to incorrect "matches" or the site being forbidden to access via runtime_blocked_hosts policy.
Ruslan Zhunus
unread,
Jan 5, 2024, 6:32:08 AM1/5/24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions, wOxxOm, Ruslan Zhunus
The creation of the shadowRoot and appRoot div in my contentScript is successful. However, I am unable to add elements like "style" to the shadow root. I noticed that I can only add them after inserting the appRoot element into my DOM, and only if the mode is set to "open". Based on this, are you suggesting that the issue lies with my implementation and not with the overall functionality?
wOxxOm
unread,
Jan 5, 2024, 6:33:31 AM1/5/24
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions, Ruslan Zhunus, wOxxOm
Your exact code works here as-is, no changes, in the content script.