0

I have a script that executes a script, but in my case the script only runs when I click on the icon: I need in my case to automatically run/inject the script when the pages loads.

My code:

chrome.browserAction.onClicked.addListener(function (tab) {
    // for the current tab, inject the "inject.js" file & execute it
    chrome.tabs.executeScript(tab.ib, {
        file: 'inject.js'
    });
});
Ahmet Emre Kilinc
  • 5,489
  • 12
  • 30
  • 42
Info E
  • 147
  • 1
  • 13
  • Possible duplicate of [On page load event in Chrome extensions](https://stackoverflow.com/questions/9862182/on-page-load-event-in-chrome-extensions) – Alexei Levenkov Nov 13 '17 at 16:41

1 Answers1

1

So after looking more closer i found this solution:

chrome.tabs.onUpdated.addListener(
  function ( tabId, changeInfo, tab )
  { 
    if ( changeInfo.status === "complete" )
    {
      chrome.tabs.executeScript({
      file: 'inject.js'
    });
  }
});
Info E
  • 147
  • 1
  • 13