0

In the following snippets, how can I make this run when tab load is done instead of click? I tried to find load event instead of chrome.browserAction.onClicked.addListener but can't find anything.

background.js

chrome.browserAction.onClicked.addListener(function (tab) {
    chrome.tabs.executeScript(tab.ib, {
        file: 'dosomething.js'
    });
});

dosomething.js

(function() {
 setTimeout(function(){  
    alert('Doing Something!...');
    $('body').css('background','red');
}, 3000);
})();

manifest.json

{
  "name": "DoingSomethng",
  "version": "0.0.1",
  "manifest_version": 2,
  "background": {
    "scripts": [
      "background.js"
    ],
    "persistent": true
  },
  "browser_action": {
    "default_title": "Something!"
  },
  "permissions": [
    "https://*/*",
    "http://*/*",
    "tabs"
  ]
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Behseini
  • 6,066
  • 23
  • 78
  • 125
  • Remove "background", "permissions", "browser_action" sections and declare a ["content_scripts"](https://developer.chrome.com/extensions/content_scripts#declaratively) section with dosomething.js in `js` key. – wOxxOm Apr 11 '20 at 06:04
  • Thanks for comment wOxxOm, I ,actually, tried this before and some how it is working but the problem is that it is happening only once! for example if I naviagte to another page ans use the Back tool at browser to comeback to the page the scripts in `dosomething.js` is not running for second time – Behseini Apr 11 '20 at 06:19
  • In Chrome content scripts run each time the page environment is created and it doesn't matter if you pressed the Back button or loaded the page normally. What happens in your case is probably a modern site that uses history/hash navigation, see [this answer](https://stackoverflow.com/a/39508954) for solutions. – wOxxOm Apr 11 '20 at 06:23

0 Answers0