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
Importing from within isolated function #21
Comments
I think there are two potential options. The first would be to pass import ContentScript from './content-script';
import { say } from 'cowsay';
chrome.runtime.onMessage.addListener((msg, sender) => {
chrome.scripting.executeScript({
target: {tabId:sender.tab.id},
func: ContentScript,
args: [secret, say],
});
}); content-script.ts export default async function(secret, say) {
console.log(say({text:secret});
} The second would be to generate a static JS file that you'd inject using chrome.runtime.onMessage.addListener((msg, sender) => {
chrome.scripting.executeScript({
target: {tabId:sender.tab.id},
files: ['outputContentScript.js'], // defined and generated by vite
});
}); content-script.ts - transpiled to outputContentScript.js at build time import { say } from 'cowsay';
console.log(say({text:secret}); The issue there would be forwarding values from the service worker context to the injected script. Could use a message from the content script to retrieve that from the service worker, though. |
Anyways, there's not really an issue with the plugin here that I can see, just intricacies of working with |
@samrum Thanks for the response -- the argument approach is indeed what I needed, very clever! I hadn't thought of that. Totally appreciate your willingness to help me out via GH issues albeit unorthodox ;) |
For anyone else who might find this same issue -- passing the function does not work in most cases. I am still trying to figure out a sane way to do this. I will likely resort to using a custom plugin. |
Not exactly sure how to approach this issue. Service Worker needs to execute a script dynamically using
chrome.scripting.executeScript
with thefunc
parameter, providing a function that will be serialized, sent across frames, and reconstructed on the other side. This creates a problem for importing anything from within the content script.service-worker.ts
content-script.ts
The text was updated successfully, but these errors were encountered: