In my chrome extension, I had a similar function in both "popup.js" and "contentScript.js", so I decided to have it in a single file instead, in "helper.js". I need to call/import that file from both popup and contentScript.
From this SO question: Import in Content Script i got the solution (not the first one listed), to simply add the file in the manifest.json, so I put this:
"content_scripts": [
{
"js": ["helper.js",
"contentScript.js"],
"matches": [
"<all_urls>"
]
}
],
"web_accessible_resources": [
{
"resources": [ "helper.js" ],
"matches": [ "<all_urls>" ]
}
],
Now, I just need to access the same file in "popup.js". Initially I tried following this: Import from popup by adding a second tag in my popup.html file, but it doesn't work, because I need to access the function name from popup.js (and not the popup window).
Specifically, I have this section of code in "popup.js" that is supposed to call a function from "helper.js" after a click event:
async function handleChat(e) {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: removeTags,
});
window.close();
}
So the question is, how do I access or reference the "removeTags" function (that is in helper.js) ?