How to prevent chrome extension content script pausing when switching tab

自作多情 提交于 2020-12-06 06:32:45

问题


I develop chrome extension. As usual I have extension button in the tool bar. On the popup I have start button. When click start then message with 'start' is sending and some process in the content script is starting. The problem is that when I switch tab or roll up (hide) the chrome - the process is paused. When I switch to tab where extension is - the process continue executing. For testing I have made simple test, the result is the same - script is paused:

var TTT = 0;
function TEST() {
    setTimeout(function () {
        TTT = TTT + 1;
        console.clear();
        console.log(TTT);
        TEST();
    }, 500)
} 

manifest:

{
   "background": {
      "scripts": [ "background.js" ]
   },
   "content_scripts": [ {
      "js": [ "libs/jquery.js", "js/js.js" ],
      "matches": [ "\u003Call_urls>" ]
   } ],
   "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
   "description": "DESCR",
   "icons": {
      "128": "images/ic_wmid.png"
   },
   "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCA98AMIIBC8KCBQEAurLyivtW46v1EZWRUryw0OYepQtEhjOkUixB5tDfXieDCZKQGEzv8ODtaOJKyAe/GEtnYKYJ50RP0FiYUUxk6p7biROiI1yt/YWajE3pVMwe8X2Iwuv2oXaUswSIlydIUkCcyiBVp5XqhCtH4/JA07QlX4g0sy8dyBSz9X0jbGcWMdvmUME52YqbnSCGuzNf/sL0hSv3NJuvG2e/mtnW4Zr9lKUYDfzc0rKOTAvQw7wlrnyFg3oadnuR1KkZM3Zt2vSE2eSlG7HF+8riwzFJZA5SIdN7i7kkXqbuprxs36qv+hJgnl4bIHEiE+MFBjujPRMaO3aFi0wLC3TCaZYIWQIDAHYE",
   "manifest_version": 2,
   "name": "NAME,
   "page_action": {
      "default_icon": {
         "19": "images/icon.png",
         "38": "images/icon.png"
      },
      "default_title": "TITLE"
   },
   "permissions": [ "activeTab", "webRequest", "webRequestBlocking", "tabs", "notifications", "http://*/*", "https://*/*" ],
   "version": "1.2",
   "web_accessible_resources": [ "images/ic_wmid48.png" ]
}

Any other files and codes I think may not touch this.

来源:https://stackoverflow.com/questions/55276518/how-to-prevent-chrome-extension-content-script-pausing-when-switching-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!