javascript - Is it possible to schedule to launch Chrome app and run certain commands periodically? - Stack Overflow

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745260234a4619178.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信