PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
8.88k stars 316 forks source link

[BUG] example with-content-scripts-ui,where the CSUI container is lost after navigating within the SPA and upon returning. #939

Open wkABXY opened 3 months ago

wkABXY commented 3 months ago

What happened?

s there a good solution to the issue of the CSUI container getting lost during single-page navigation? This problem also exists in the official example with-content-scripts-ui, where the CSUI container is lost after navigating within the SPA and upon returning. 448792262860abd80b709a808610326 fc48e7ec97f9286385afde5292189c6 db3593953bc6689578b516a7d04a512 58e5991e39ce9239088071c2de0286d

Version

Latest

What OS are you seeing the problem on?

No response

What browsers are you seeing the problem on?

No response

Relevant log output

No response

(OPTIONAL) Contribution

Code of Conduct

pwli0755 commented 3 months ago

same here, is there a way to hook something like afterNavigateEnd?

window.navigation.addEventListener("navigate", (event) => {
    console.log('location changed!', 'from: ', document.URL, 'to: ', event.destination.url);

    if (event.destination.url.includes("login")) {
        console.log(
            "hi there"
        )
        // do some html injection
        // the question is, this logic runs at the time when navigate happens, not when navigate ends
    }
})

Note that I want to do the injection only when the document.URL includes "login", how can I achive that without using setTimeout()?