if you have an extension with multiple content scripts injected into a single page, is it possible to address a specific content script on the page rather than broadcasting to all content scripts? Thanks!

有帮助吗?

解决方案

If I understand you correctly, you could execute your content scripts in your background.js instead of defining it in your manifest.json:

if (condition) {
  chrome.tabs.executeScript(null, { file: 'contentscript1.js' });
} else {
  chrome.tabs.executeScript(null, { file: 'contentscript2.js' });
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top