question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC | Optionally shadowing DOM in Content Script UI

See original GitHub issue

How 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:closed
  • Created a year ago
  • Reactions:2
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
louisgvcommented, Jun 8, 2022

@louisgv That seems to work perfectly! I do have a question though, does getRootContainer support both sync and async methods? If not, I think it should. If it does then perfect👌

Thanks for implementing that so quickly 🔥

It supports both async and sync 😃

1reaction
louisgvcommented, Jun 8, 2022

Thank you for the example implementation 😄

I thought about using the config itself to tweak the mounting component. 2 issues I had in mind:

  1. We would need to clean them up (so that when we construct the final manifest, we don’t include those non-manifest properties).
  2. The casing - I prefer camelCase instead of snake_case for TypeScript in general.

I think it might be better to separate mountPoint from mountRoot. 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found