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

How to config the webpack properly to include the contentscript js file via executeScript? #40

Open
cyfung1031 opened this issue May 27, 2023 · 1 comment

Comments

@cyfung1031
Copy link

For some reasons, i want to executeScript from the background.js

chrome.scripting.executeScript(
          {
            target: { tabId: aTab.id },
            files: [
              // get selection, send it to background (here), wait for response, replace selection
              "/my_content_script.js"
            ]
          });

However, in such a case, the my_content_script.js is not recognised by the webpack. I have to put it in public instead of src.

Any suggestion ? or just put into public ?

@tk-kushal
Copy link

tk-kushal commented Feb 14, 2024

If you just want to execute script using background.js then there is no need for re-configuration, just leave it as it is and exclude it from manifest.json:

The content script is injected by manifest.json at webpage load time, you just need to remove the injection from there and inject it from background.js

Webpack is simply bundling the file, it does not affect how the file is injected.

If you want to exclude the content.js file from being bundled just put it in the public folder as you mentioned earlier.

I hope this helps, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants