Skip to content

[BUG] contents_script Custom Root Container cann't append a child #577

@czqgithub2017

Description

@czqgithub2017

What happened?

I want to add a child element under the ”nav“ element once the nav sub elements have fully loaded. However, my current code is replacing all the existing children under the "nav".

the html:
"
_

aaa
bbb
_ "

script:
**export const getRootContainer = () =>
new Promise((resolve) => {
const checkInterval = setInterval(() => {
const rootContainer = document.querySelector("nav")
if (rootContainer) {
clearInterval(checkInterval)
resolve(rootContainer)
}
}, 137)
})

const PlasmoOverlay = () => {
return (

<span
style={{
background: "yellow",
padding: 12
}}>
HELLO WORLD ROOT CONTAINER

) }

export const render = async ({ createRootContainer }) => {
const rootContainer = await createRootContainer()
const root = createRoot(rootContainer)
root.render()
}

export default PlasmoOverlay**

Version

Latest

What OS are you seeing the problem on?

Windows

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

(OPTIONAL) Contact Details

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I checked the current issues for duplicate problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions