Answer the question
In order to leave comments, you need to log in
How to enable import/export inside chrome.tabs.executeScript?
I am making a chrome plugin for my needs. Not an expert on the subject. Modularity for background.js and popup.js works, I just put it in html
and everything is ok, imports / exports work.
But here is such a case, an example of code in background.js:
<script type="module"...
chrome.tabs.onUpdated.addListener((tabId, _, tab) => {
if(tab.url.match(/^myRegexpHere$/) )
chrome.tabs.executeScript(tabId, { file: 'background/something.js' })
});
Answer the question
In order to leave comments, you need to log in
In short, the answer to your own question turned out to be a decent footcloth. The current solution is in the second part of the answer, and in the first summary from the discussion on stackoverflow.
In general, here is a question on stackoverflow under which the most different solutions were collected https://stackoverflow.com/questions/48104433/how-t...
What I understood from all this:
chrome.tabs.executeScript(tabId, { code: 'globalThis.path = "folder/your_content_script.js"'}, () => {
chrome.tabs.executeScript(tabId, { file: 'folder/middle.js' })
})
(async () => await import(chrome.runtime.getURL(globalThis.path)))()
function executeImportedScript(tabId, path) {
chrome.tabs.executeScript(tabId, { code: `globalThis.path = '${path}'`}, () => {
chrome.tabs.executeScript(tabId, { file: 'folder/middle.js' })
})
}
executeImportedScript(tabId, "folder/your_content_script.js")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question