Alexander Loktiev
Alexander Loktiev

Reputation: 51

How to execute chrome extension by schedule in background js

I have a question. I need to execute my extension every some period of time, but I can`t, because my script is executed only when popap is open. I would want it started to work after opening chrome browser.

It`s my manifest.json:

"name": "MyExt",
"version": "1.0",
"description": " 'It`s my extension",
"background": {
    "scripts": ["js/core.js"],
    "persistent": true
},
"icons": {
    "128" : "icon.png"
},
"browser_action": {
    "default_icon": "ext.png",
    "default_title": "MyExt",
    "default_popup": "index.html"
 },

Upvotes: 1

Views: 2794

Answers (2)

TP-O
TP-O

Reputation: 65

You can use chrome.alarms to execute script by schedule.

Upvotes: 3

Balsa Lazarevic
Balsa Lazarevic

Reputation: 83

In short, no, you cannot execute the code in time intervals. What you can do is register an eventListener in background.js (or whatever you decide to name it) and execute the code you put in there when the event happens(extension is installed, there is an available update either for your extension or for Chrome etc.).

On the link below you can see all the available event listeners: https://developer.chrome.com/extensions/runtime#events

Upvotes: 0

Related Questions