I am trying to inject code after detecting bookmark created .
**manifest.json**
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": ["storage", "activeTab",
"scripting","pageCapture","bookmarks","tabs","contextMenus"],
"host_permissions": ["http://localhost/*", "*://*/*"],
**Background.js**
function greeting() {
console.log("dynamic content script injected");
document.body.style.backgroundColor = 'orange';
}
chrome.bookmarks.onCreated.addListener( () => {
console.log("Bookmark created");
chrome.tabs.query({currentWindow: true, active: true}), function (tabArray) {
chrome.scripting.executeScript(
{
target: {tabId: tabArray[tabArray.length - 1].id},
function : greeting
})
}
});
The function "greeting" never gets executed. I did try lastFocusedWindow: true property in chrome.tabs.query() also but it still does not run.