I am trying to create a Chrome extension that automatically generates a small pop up on the side when the user navigates to a particular site.
I went through the documentation on Chrome's developer page & followed the tutorial but I am not sure how to inject a script when the user visits a particular site. I want the popup to show up only on that particular site. In fact I don't see any console logs inside the addListener section of my background.json
manifest.json
{
"name": "Google helper",
"version": "1.0",
"manifest_version": 3,
"description": "Shows you additional information on google",
"icons": {
"128": "icon128.png"
},
"action": {
"default_icon": {
"128": "icon128.png"
},
"default_title": "Google helper",
"default_popup": "popup.html"
},
"background": {
"service_worker": "background.js"
},
"permissions": [
"tabs",
"activeTab",
"scripting"
// ,
// "https://google.com/"
]
}
background.js
// Register the service worker
console.log("Here in background.js before anything starts"); // Able to see this log in service worker view
// Called when the user clicks on the action.
chrome.action.onClicked.addListener(function(tab) {
// No tabs or host permissions needed!
console.log('Turning ' + tab.url + ' red!'); // Don't see this in logs
chrome.scripting.executeScript({
code: 'document.body.style.backgroundColor="red"'
});
});