RFC | Optionally shadowing DOM in Content Script UI
See original GitHub issueHow do you envision this feature/change to look/work like?
Shadowing DOM is good for isolating app components. but still there needs to be inject directly in some use cases.
What is the purpose of this change/feature? Why?
Provide options for users who want their plugins work seamlessly with pre-exsiting site or something.
(OPTIONAL) Example implementations
provide options for content script:
export const config: PlasmoContentScript = {
matches: ['https://github.com/*'],
css: ['../assets/style.css'],
inject_directly: false
}
template modification for cli/plasmo/templates/static/content-script-ui-mount.tsx
:
window.addEventListener("load", () => {
const useShadowRoot = Mount.config.inject_directly ?? true
const mountPoint = useShadowRoot
? document.createElement("div")
: Mount.getMountPoint() // inject app into target element directly
if (useShadowRoot) {
mountPoint.style.cssText = `
z-index: 1;
position: absolute;
`
const shadowHost = document.createElement("div")
const shadowRoot = shadowHost.attachShadow({ mode: "open" })
document.body.insertAdjacentElement("beforebegin", shadowHost)
shadowRoot.appendChild(mountPoint)
}
const root = createRoot(mountPoint)
root.render(<MountContainer />)
})
(OPTIONAL) Contact Details
No response
Verify canary release
- I verified that the issue exists in
plasmo
canary release
Code of Conduct
- I agree to follow this project’s Code of Conduct
- I checked the current issues for duplicate problems.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Shadow DOM - W3C
To assign slotables for a tree , given a tree tree and an optional set of slots noSignalSlots (empty unless stated otherwise), run...
Read more >Is a Closed Shadow DOM within Content Script Secure?
This article talks about there being a false sense of security when using closed mode because "There's nothing stopping an attacker from ...
Read more >Using shadow DOM - Web Components | MDN
Shadow DOM allows hidden DOM trees to be attached to elements in the regular DOM tree — this shadow DOM tree starts with...
Read more >Working with Shadow DOM - Lit.dev
Lit components use shadow DOM to encapsulate their DOM. Shadow DOM provides a way to add a separate isolated and encapsulated DOM tree...
Read more >html-standard.pdf
1.7.1 Serializability of script execution . ... 1.11.3 Restrictions on content models and on attribute values. ... 2.7.3 The DOMStringList interface.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It supports both async and sync 😃
Thank you for the example implementation 😄
I thought about using the config itself to tweak the mounting component. 2 issues I had in mind:
camelCase
instead ofsnake_case
for TypeScript in general.I think it might be better to separate
mountPoint
frommountRoot
. The “mountPoint” concept is Plasmo’s abstraction over how we make the component hover on top of some element on the page. On the other hand, the root component is supposed to be the parent of the mountPoint.I think we should make another function called
getMountRoot
-> this would accomplish both the config override and prevent coupling these two concepts.