Chrome extension: Execute background page only once when chrome starts

前端 未结 3 1999
旧巷少年郎
旧巷少年郎 2021-02-03 14:12

I am playing with chrome extensions, my manifest loads a background page with:

...
"background": { "scripts": ["background_page.js"]         


        
3条回答
  •  -上瘾入骨i
    2021-02-03 14:56

    To expand on quackkkk's answer, omitting the "persistent" key in the manifest.json is the same as setting it to "persistent": true

    The proof:

    In the docs, it says that:

    The only occasion to keep a background script persistently active is if the extension uses chrome.webRequest API to block or modify network requests. The webRequest API is incompatible with non-persistent background pages.

    with that in mind, we can check out the manifest.json one of the extension sample projects, No Cookies, that uses the webRequest API and see that it does not explicitly set "persistent"

提交回复
热议问题