如何为Google Chrome扩展程序使用chrome.alarms [英] How to use chrome.alarms for Google Chrome extension

查看:544
本文介绍了如何为Google Chrome扩展程序使用chrome.alarms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


manifest_version:2,$ b
$ bname:App name,
description:说明转到这里,
version:1.0,
background:{
脚本:[background.js]
},
权限:[
标签,
警报
],
browser_action:{
default_icon:icon.png,
default_popup:popup.html
}
}

我试图创建一个函数来每分钟创建一个伟大的弹出窗口,如下所示:

  chrome.alarms.onAlarm.addListener(function(){
alert('great');
});

有人可以告诉为什么它不触发该警报。我检查控制台,没有显示错误。谢谢。

解决方案

您没有创建任何闹钟,所以没有 onAlarm
$ b

使用 chrome.alarms.create 。注意:您应该在 chrome.runtime.onInstalled 事件中执行此操作。

manifest.json

{
    "manifest_version": 2,
    "name": "App name",
    "description": "Description goes here",
    "version": "1.0",    
    "background": {
        "scripts": ["background.js"]
    },
    "permissions": [
        "tabs",
        "alarms"
    ],
    "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
    }
}

I trying to create a function to make a popup "great" every minute like this:

chrome.alarms.onAlarm.addListener(function(){
        alert('great');
    });

Could someone please tell why is it not triggering that alert. I check the console, no error was displayed. Thanks.

解决方案

You didn't create any alarm, so no onAlarm event will be fired.

Create an alarm with chrome.alarms.create. Note: you should do it in the chrome.runtime.onInstalled event.

这篇关于如何为Google Chrome扩展程序使用chrome.alarms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆