admin管理员组

文章数量:1417070

I've developed some Chrome apps and Chrome extensions these day for fun.

and I'm wondering if I can schedule launch Chrome app and run certain mands periodically like cron jobs.

I know Chrome provide "chrome.alarm api" to run a certain function periodically, but I believe it requires users to keep my chrome app open or to keep chrome browser open which my chrome extension is installed to.

Please tell me if I can do such a thing in the first of all, and if I can do, please tell me how I can acplish that!

I've developed some Chrome apps and Chrome extensions these day for fun.

and I'm wondering if I can schedule launch Chrome app and run certain mands periodically like cron jobs.

I know Chrome provide "chrome.alarm api" to run a certain function periodically, but I believe it requires users to keep my chrome app open or to keep chrome browser open which my chrome extension is installed to.

Please tell me if I can do such a thing in the first of all, and if I can do, please tell me how I can acplish that!

Share Improve this question edited Sep 4, 2014 at 12:51 abraham 48k10 gold badges107 silver badges157 bronze badges asked Sep 4, 2014 at 7:25 W3QW3Q 9091 gold badge12 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

A Chrome App doesn't have to be running to use the chrome.alarms API. See https://developer.chrome./apps/alarms for details about how to use it.

Basically, here's how it works:

// background page (aka event page)

chrome.alarms.onAlarm.addListener(function() {
  // Do something useful...
});

// Register an alarm that will wake my background page every hour.
chrome.alarms.create('', { periodInMinutes: 60 });

For info, here are some good Chrome App samples that use chrome.alarms at https://github./GoogleChrome/chrome-app-samples/search?utf8=%E2%9C%93&q=alarms

A Chrome Extension can stay active even before/after Chrome is launched, unless the user specifically forbids that. Kind of like Google Now operates in recent Chrome versions.

For that, you need to declare "background" permission.

Makes Chrome start up early and and shut down late, so that apps and extensions can have a longer life.

When any installed hosted app, packaged app, or extension has "background" permission, Chrome runs (invisibly) as soon as the user logs into their puter—before the user launches Chrome. The "background" permission also makes Chrome continue running (even after its last window is closed) until the user explicitly quits Chrome.

I'm afraid it's not an option for a Chrome App though. The wording in the documentation refers to deprecated legacy app types. See François's answer for a possible solution in Apps.

本文标签: