How to inject content script in chrome extensions own webpage

Skip to first unread message

Moe Bazzi

Sep 27, 2022, 12:59:50 PM9/27/22
to Chromium Extensions

lets say I open a new tab with one of my extensions pages example.html, is it possible to inject a content script into this webpage? I could add the content script as a source in the html file, but thats not what im talking about. Im talking about injection via manifest or the chrome scripting api.

Thanks in advance.


Sep 28, 2022, 8:09:45 AM9/28/22
to Chromium Extensions,
No, it's not a web page as far as the API is concerned, although it is indeed built using web technologies. It's also not a content script that you add in the html. Content script is a special kind of script that runs in an isolated world context from a foreign web page. Your extension page is not foreign, it is domestic, it doesn't have an isolated and you wouldn't want one here anyway.

In extension pages you can simply create a new <script> element and set its `src` property to the name of your extension script.

You can even do it from the outside if you opened the page via or chrome.extension.getViews() if the caller is another extension page (such as the popup/options page) or use messaging (chrome.tabs.sendMessage, BroadcastChannel,  navigator.serviceWorker) if the caller is the service worker.

Reply all
Reply to author
0 new messages