I'm creating a simple Chrome Extension with a popup, background script and a content script which I want to inject programmatically.
When a user clicks a button I want the extension to create a new tab with a url provided from the user and execute a content script on that page.
My approach is to send a message from the popup to my background script and run the following code:
chrome.tabs.create({ url }, () => {
chrome.tabs.executeScript({ file: 'content.js' });
});
But this fails and tells me that my extension doesn't have the correct permissions, even though I have permissions set to ["activeTab"]
.
The problem is that I would prefer not to have permissions to execute on every url, e.g. ["https://*/*", "http://*/*"]
(It would probably seem suspicious, but might be my only solution).
I have set up an example repo here: https://github.com/adambrgmn/test-extension. It can be loaded into Chrome as an extension.
Has anyone else encountered this problem? Any workarounds?