Search code examples
javascriptgoogle-chrome-extension

why is this chrome content-script not getting injected?


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.


Solution

  • It was just a typo . I relied too much on auto completion.

    Thanks wOxxOm for pointing it out.

    You have a typo: the ) before function(abArray) should be moved after the lone closing } below.