是否可以安排启动Chrome应用并定期运行某些命令?

W3Q*_*W3Q 1 javascript google-chrome google-chrome-extension google-chrome-app

我今天开发了一些Chrome应用和Chrome扩展程序以获得乐趣.

我想知道我是否可以安排启动Chrome应用程序并定期运行某些命令,如cron作业.

我知道Chrome会提供"chrome.alarm api"来定期运行某个功能,但我相信它需要用户保持我的Chrome应用程序处于打开状态,或者保持我的chrome扩展程序安装到的Chrome浏览器打开.

请告诉我,如果我能在第一时间做这样的事情,如果我能做到,请告诉我如何才能做到这一点!

Fra*_*ort 6

无需运行Chrome应用即可使用该chrome.alarmsAPI.有关如何使用它的详细信息,请参阅https://developer.chrome.com/apps/alarms.

基本上,这是它的工作原理:

// 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 });
Run Code Online (Sandbox Code Playgroud)

对于信息,这里是使用一些很好的Chrome应用样品chrome.alarmshttps://github.com/GoogleChrome/chrome-app-samples/search?utf8=%E2%9C%93&q=alarms