Erskine Williams
PD🧩 Plasmo Developers
•Created by Erskine Williams on 4/26/2024 in #🔰newbie
Loading a content script on a specific tab
Howdy folks,
I'm wanting to explicitly load a content script on a specific tab, so it doesn't interfere with other tabs. I have this working outside of Plasmo using the following:
await chrome.scripting.executeScript({
target: { tabId: tabID },
files: ["myContentScript.js"],
});
But I'm having difficulty getting plasmo to compile myContentScript.ts to myContentScript.js such that the extension can load it at runtime.
When I put myContentScript.ts at the root of the project, it doesn't seem to get compiled at all, so after reading this page https://docs.plasmo.com/framework/content-scripts#adding-multiple-content-scripts,
I created a contents/ folder to house this script, but it gets compiled to myContentScript.632856eb.js, and so the above code can't find the file to inject.
It appears as though the framework assumes all scripts will run wherever the url matches, but I want to inject it only on a specific tab.
Any thoughts?
5 replies