Chrome Browser Extension Development Series IX: Chrome browser's chrome.alarms.* API

Source: Internet
Author: User

Through the chrome.alarms.* API, the Chrome browser Extender can make plans to execute code periodically, or execute code at a specified time.

To use the chrome.alarms.* API, you first need to declare the alarms authorization in the Manifest.json file as follows:

{

"Permissions": [

"Alarms"

],

}

The properties of the Chrome.alarms.Alarm object are as follows:

Optional

Property name

Type

Required/ optional

Comment

name

string

Required

Alarm name

Scheduledtime

Double

Required

Time to trigger alarm, Unit MS

Double

Non-null indicates the interval of alarm periodic execution, unit minute

Common methods in the Chrome.alarms API:

· Create a alarm

Chrome.alarms.create (string name, Object Alarminfo)

This is a synchronous method, the Name property is optional, and is empty for "". The properties of the Alarminfo object are as follows:

Property name

Type

Required/ optional

comments

when

Double

Optional

Time to trigger alarm, Unit MS

Delayinminutes

Double

Optional

Onalarm Event issue delay time, Unit minute

Periodinminutes

Double

Optional

Non-null indicates the interval of alarm periodic execution, in units minute

Creates a new alarm at the time specified by Alarminfo and issues the Onalarm event. If there are already duplicate alarm, replace the existing alarm.

To reduce the effect of creating alarm on operational efficiency, the Chrome browser restricts up to one alarm in a minute, and any alarm that might break that limit will be postponed any time. Of course, there is no such limit during debugging.

· Gets the alarm of the specified name

Chrome.alarms.get (string name, function (Alarm Alarm) {...})

· Get all Alarm

Chrome.alarms.getAll (function (array of Alarm alarms) {...})

· Delete Alarm by name

Chrome.alarms.clear (string name, function (Boolean wascleared) {...})

· Clear all Alarm

Chrome.alarms.clearAll (Function (Boolean wascleared) {...})

· Listen for events that occur in alarm for the event page

Chrome.alarms.onAlarm.addListener (function (Alarm Alarm) {...})

The alarm in the callback function is the alarm object that triggered the event.

Chrome Browser Extension Development Series IX: Chrome browser's chrome.alarms.* API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.