Chrome扩展API的警报有方法明确,是不按文档工作

Chrome extension API for alarms has method clear that is not working as per documentation

本文关键字:工作 文档 API 扩展 有方法 Chrome      更新时间:2023-09-26

Chrome版本为33.0.1750.154 m.

根据http://developer.chrome.com/extensions/alarms#method-clear上的文档,clear方法的签名是:chrome.alarms。清除(字符串名称,函数回调)。

我的扩展中有一个仍在开发中的警报:

chrome.alarms.get('refreshForNotification', function(alarm){
    console.log('>>>' + JSON.stringify(alarm));
});
>>>{"name":"refreshForNotification","periodInMinutes":2,"scheduledTime":1395892890429.581} 

现在,当我尝试使用

清除此警报时:
chrome.alarms.clear('refreshForNotification', function(wasCleared){
    console.log('>>> wasCleared: ' + wasCleared);
});

我得到以下错误:

Error: Invocation of form alarms.clear(string, function) doesn't match definition alarms.clear(optional string name)
 message: "Invocation of form alarms.clear(string, function) doesn't match definition alarms.clear(optional string name)"

有没有人能告诉我这里出了什么问题?警报api是稳定的从chrome 22按文档。如果我的代码没有错,那么要么文档是旧的,要么文档太新,当前在我的chrome上的行为将在未来改变。

任何提示/帮助都是有用的。

谢谢

上周在http://crrev.com/258526 (Chrome 35.0.1903.0+)中添加了chrome.alarms.clear的可选回调。在线文档显示了最新(开发)版本的可用特性,而不是稳定版本。

Chrome 35目前在开发者频道可用,所以如果你真的想使用这个功能,那么你可以从这里安装Chrome。

在35.0.1905.3:

manifest.json

{
  "name": "22692926 Example",
  "description": "alarms",
  "version": "1.0",
  "manifest_version": 2,
  "permissions": ["alarms"],
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  }
}

background.js

var NAME = "foo";
var alarmInfo = {
  'delayInMinutes': 1
};
chrome.alarms.create(NAME, alarmInfo);
chrome.alarms.get(NAME, function(a) { console.log(a); });
chrome.alarms.clear(NAME, function(wasCleared) { console.log(wasCleared); });

输出
Object {name: "foo", ...}
true

我知道这不能直接回答你的问题,但也许你可以做一个测试扩展复制这段代码,如果它的工作,你可以比较它与你的,找出有什么不同。