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?
Plasmo Docs
Content Scripts – Plasmo
How to use Plasmo content scripts to inject custom behavior into web pages
Rob
Rob•21d ago
In my BGSW, I did this:
import contentTs from "url:~contents/content.ts";

const getFilenameFromImport = (fullFileName: string) => {
const split = fullFileName.split("/").pop();
if (split === undefined)
throw new Error(
`Issue parsing filename in background.ts: ${fullFileName}`
);
const filename = split.split("?")[0];
return filename;
};

const contentTsFilename = getFilenameFromImport(contentTs);
import contentTs from "url:~contents/content.ts";

const getFilenameFromImport = (fullFileName: string) => {
const split = fullFileName.split("/").pop();
if (split === undefined)
throw new Error(
`Issue parsing filename in background.ts: ${fullFileName}`
);
const filename = split.split("?")[0];
return filename;
};

const contentTsFilename = getFilenameFromImport(contentTs);
Then I passed contentTsFilename to chrome.scripting.executeScript. As far as I know, there isn't a more "official" way of doing this
Erskine Williams
Erskine Williams•20d ago
Yikes! Ok, I'm very grateful for your response. I will give it a go. This did the trick! Thanks for the assist!
Rob
Rob•20d ago
No problem!