Google chrome extension 在chrome extension中安装后如何执行扩展的自动刷新
您好,我需要知道是否有任何方法可以在安装后自动刷新扩展。目前我正在使用警报刷新扩展。但我需要在安装后自动刷新扩展。有任何方法可以执行吗?请帮助我。下面是我使用警报的代码。 这是我的background.jsGoogle chrome extension 在chrome extension中安装后如何执行扩展的自动刷新,google-chrome-extension,Google Chrome Extension,您好,我需要知道是否有任何方法可以在安装后自动刷新扩展。目前我正在使用警报刷新扩展。但我需要在安装后自动刷新扩展。有任何方法可以执行吗?请帮助我。下面是我使用警报的代码。 这是我的background.js var oldChromeVersion = !chrome.runtime; function getGmailUrl() { return "http://calpinemate.com/"; } function isGmailUrl(url) { return
var oldChromeVersion = !chrome.runtime;
function getGmailUrl() {
return "http://calpinemate.com/";
}
function isGmailUrl(url) {
return url.indexOf(getGmailUrl()) == 0;
}
if (chrome.runtime && chrome.runtime.onStartup) {
chrome.runtime.onStartup.addListener(function() {
updateIcon();
});
} else {
chrome.windows.onCreated.addListener(function() {
updateIcon();
});
}
function onInit() {
updateIcon();
if (!oldChromeVersion) {
chrome.alarms.create('watchdog', {periodInMinutes:5});
}
}
function onAlarm(alarm) {
console.log('Got alarm', alarm);
if (alarm && alarm.name == 'watchdog') {
onWatchdog();
}
else {
updateIcon();
}
}
function onWatchdog() {
chrome.alarms.get('refresh', function(alarm) {
if (alarm) {
console.log('Refresh alarm exists.');
}
else {
updateIcon();
}
});
}
if (oldChromeVersion) {
updateIcon();
onInit();
}
else {
chrome.runtime.onInstalled.addListener(onInit);
chrome.alarms.onAlarm.addListener(onAlarm);
}
function updateIcon(){
.....//certain functions are performed
}
为了在安装扩展时运行操作(这与禁用和重新启用完全不同): 替换该行:
chrome.alarms.create('watchdog', {periodInMinutes:5});
这一行:
chrome.alarms.create('watchdog', {
periodInMinutes: 5,
delayInMinutes: 0
});
如果希望在启用扩展时运行操作: 在文件最末尾的新行中添加以下内容:
onInit();
目前,在启用扩展并重新加载后,它只执行上述功能。我需要它在重新加载扩展之前执行。请将您的代码更改为再现您的问题的尽可能小的示例。目前,代码似乎比您要问的具体问题要大得多。还有,这和Linux有什么关系?我已经更新了我的代码。请检查一下