Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.alarms returns undefined

Good morning, wizards.

I'm trying myself in writing an extension for chromium-browser. The version of chromium is 18.0.1025.151 (development build 130497 Linux) Built on Ubuntu 12.04, running on Ubuntu 12.10

My OS is ubuntu GNU/Linux 12.04.1 (LTS), 64bit.

The problem is: I cannot use chrome.alarms. I get 'undefined' when access this variable.

Part of my manifest.json:

  "background": {
      "scripts": ["background.js"]
    },
  "permissions": [
    "alarms",
    "tabs",
    "http://*/*"
  ],

Part of my background.js:

chrome.alarms.onAlarm.addListener(function(alarm) {
    if (! alarm.name.match ('/^extension47_.*/'))
        return;
    alert ('extension47 fired an alarm!');
});

What I get:

Uncaught TypeError: Cannot read property 'onAlarm' of undefined

at the line chrome.alarms.onAlarm.addListener.

When I go to the chromium console from the extensions page, auto-completion suggests me no chrome.alarms. Obviously, when I type there chrome.alarms, I really get undefined. Why so?..

I'm totally stuck, failed to find a solution anywhere on the Internet, what am I doing wrong?

like image 871
gluk47 Avatar asked Dec 04 '22 13:12

gluk47


1 Answers

I had some trouble with this too recently and didn't see that noted anywhere in the docs (or at any relevant location).

Just make sure to also ask for the alarms permission:

manifest.json

{
    "manifest_version": 2,
    "permissions": [
        // ...  
        "alarms"
    ]
}
like image 134
Simon Boudrias Avatar answered Jan 16 '23 16:01

Simon Boudrias