chrome.extension.getBackgroundPage() returns null after awhile

后端 未结 2 1681
轮回少年
轮回少年 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:57

    According to the referenced page (Difference between Event and Background Page) there is a better option to get the background while still using Event Page :

    If your extension uses, extension.getBackgroundPage, switch to runtime.getBackgroundPage instead. The newer method is asynchronous so that it can start the event page if necessary before returning it.

    This worked well for me, just do your job in the asynchronous callback, which receives the background page as a function parameter.

    Here is the specification of the method runtime.getBackgroundPage

提交回复
热议问题