chrome.extension.getBackgroundPage() returns null after awhile

后端 未结 2 1651
轮回少年
轮回少年 2021-01-13 15:47

When my chrome extension loads on chrome startup, everything seems to be ok and chrome.extension.getBackgroundPage() returns the right value (lunched from popup.js). But aft

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-13 15:50

    Change your background(Event Page) to a real background Page.

    Modify your manifest file from

    "background": {
            "scripts": [
                "background.js"
            ],
            "persistent": false
        }
    

    to

    "background": {
            "scripts": [
                "background.js"
            ],
            "persistent": true
        }
    

    Event pages are very similar to background pages, with one important difference: event pages are loaded only when they are needed. When the event page is not actively doing something, it is unloaded, freeing memory and other system resources.

    Reference

    • Difference between Event and Background Page

提交回复
热议问题