3

Chrome version is 33.0.1750.154 m.

As per the documentation at http://developer.chrome.com/extensions/alarms#method-clear, the signature of clear method is: chrome.alarms.clear(string name, function callback).

I have an alarm in my extension which is still under development:

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

Now, when I try to clear this alarm with:

chrome.alarms.clear('refreshForNotification', function(wasCleared){
    console.log('>>> wasCleared: ' + wasCleared);
});

I am getting the below error:

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)"

Can someone please guide/point me what is going wrong here? The alarms api is stable from chrome 22 as per documentation. If my code is not wrong, then either documentation is old or documentation is too new and current behaviour on my chrome will change in future.

Any hints/help will be useful.

Thanks

  • This `callback` feature was added 7 days ago: http://crrev.com/258526/ If you want to use the feature, then you have to use a developer/canary build of Chrome. If you're on stable, then you have to wait about 12 weeks. – Rob W Mar 29 '14 at 00:48
  • Thanks for that information! I hope I was allowed by stackoverflow to accept this comment as solution. – Shreyas Purohit Mar 29 '14 at 20:28

2 Answers2

3

The optional callback of chrome.alarms.clear was added last week in http://crrev.com/258526 (Chrome 35.0.1903.0+). The online documentation shows the available features for the latest (dev) version, not the stable version.

Chrome 35 is currently available on the developer channel, so if you really want to use this feature, then you can install Chrome from here.

Rob W
  • 315,396
  • 71
  • 752
  • 644
0

This works fine for me on 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); });

output

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

I know this doesn't directly answer your question, but perhaps you can make a test extension copying this code exactly, and if it works, you can compare it to yours and figure out what's different.

sowbug
  • 4,508
  • 19
  • 28