Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] When installing or updating a plugin, content will not be automatically injected into the opened tab page. #1002

Open
2 of 3 tasks
duriann opened this issue Jun 16, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@duriann
Copy link

duriann commented Jun 16, 2024

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.
@duriann duriann added the bug Something isn't working label Jun 16, 2024
@duriann duriann closed this as completed Jun 17, 2024
@duriann duriann reopened this Jun 17, 2024
@rezamajidi
Copy link

@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
Copy link
Author

duriann commented Jun 19, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants