[BUG] When installing or updating a plugin, content will not be automatically injected into the opened tab page.
duriann opened this issue · 3 comments
duriann commented
What happened?
When installing or updating a plugin, content will not be automatically injected into the opened tab page.
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
- I would like to fix this BUG via a PR
Code of Conduct
- I agree to follow this project's Code of Conduct
- I checked the current issues for duplicate problems.
rezamajidi commented
@duriann I also had this problem and currently using this workaround to fix that:
Maybe it helps.
if (details.reason === "install" || details.reason === "update") {
for (const cs of chrome.runtime.getManifest().content_scripts) {
for (const tab of await chrome.tabs.query({ url: cs.matches })) {
if (tab.url.match(/(chrome|chrome-extension):\/\//gi)) {
continue
}
chrome.scripting.executeScript({
files: cs.js,
target: { tabId: tab.id, allFrames: cs.all_frames },
injectImmediately: cs.run_at === "document_start"
})
}
}
}
duriann commented
@duriann I also had this problem and currently using this workaround to fix that: Maybe it helps.
if (details.reason === "install" || details.reason === "update") { for (const cs of chrome.runtime.getManifest().content_scripts) { for (const tab of await chrome.tabs.query({ url: cs.matches })) { if (tab.url.match(/(chrome|chrome-extension):\/\//gi)) { continue } chrome.scripting.executeScript({ files: cs.js, target: { tabId: tab.id, allFrames: cs.all_frames }, injectImmediately: cs.run_at === "document_start" }) } } }
I did the same thing, but the plasmo-csui node will be added repeatedly on the injection page, and the console will keep prompting: Error: Extension context invalidated. This is because the old context is not uninstalled after injection. Do you have any solution?