如何重新加载后台脚本?
How to reload background scripts?
根据 MDN,
Background scripts are loaded as soon as the extension is loaded and stay loaded until the extension is disabled or uninstalled.
我的后台脚本根据用户的选项更改其行为,存储在 localStorage 中。当用户更改选项(使用 options_ui
)时,localStorage 会更新,但由于后台脚本保持加载状态,用户选项不会被接受。如果重新加载浏览器,则会启用选项。
如何在用户更改选项后重新加载后台脚本?
说的可以chrome.runtime.reload()
,不过最好发消息到后台脚本更新。
像这样:
chrome.runtime.onMessage.addListener( function(request, sender)
updateOption(request.option1)
});
在option.js中:
chrome.storage.sync.set({'option1': 'new_value'}); ....
chrome.tabs.sendMessage(tab, {option1: 'new_value'});
亲切的问候
根据 MDN,
Background scripts are loaded as soon as the extension is loaded and stay loaded until the extension is disabled or uninstalled.
我的后台脚本根据用户的选项更改其行为,存储在 localStorage 中。当用户更改选项(使用 options_ui
)时,localStorage 会更新,但由于后台脚本保持加载状态,用户选项不会被接受。如果重新加载浏览器,则会启用选项。
如何在用户更改选项后重新加载后台脚本?
说的可以chrome.runtime.reload()
,不过最好发消息到后台脚本更新。
像这样:
chrome.runtime.onMessage.addListener( function(request, sender)
updateOption(request.option1)
});
在option.js中:
chrome.storage.sync.set({'option1': 'new_value'}); ....
chrome.tabs.sendMessage(tab, {option1: 'new_value'});
亲切的问候