gpt4 book ai didi

javascript - 有没有地方可以放置您希望在用户第一次下载/打开您的 chrome 扩展程序时运行的 Javascript 代码?

转载 作者:行者123 更新时间:2023-11-30 19:22:02 26 4
gpt4 key购买 nike

我正在制作一个 chrome 扩展程序,如果用户已登录,我想存储信息。我检查的方法是在字段上运行 chrome.storage.get 以说明他们是否已登录。但是,当用户第一次下载应用程序时,没有存储任何值,chrome.storage.get 返回错误。

最佳答案

您可以利用 onInstalled来自 chrome.runtime API 的方法:

Fired when the extension is first installed, when the extension is updated to a new version, and when Chrome is updated to a new version.

示例:

chrome.runtime.onInstalled.addListener(function(reason) {
if (reason === 'install') {
// Your init code
}
});

reason 也可以等于"update"。这允许您在您的扩展刚刚更新时运行代码。

关于javascript - 有没有地方可以放置您希望在用户第一次下载/打开您的 chrome 扩展程序时运行的 Javascript 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57341297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com