Background Tasks
Posted: Fri Nov 25, 2016 2:20 pm
Hello Coders,
Let's say you want to create an extension that needs to do some work in the background, a good example would be an RSS feed. Now you'll probably want your extension to check every now and then to see if anything new has been added to the feed and alert the user that new content is available.
This is quite easy to accomplish.
In your manifest.json file add the background permission:
Here's an example background.js file which updates the extension badge text every second:
Happy coding
Let's say you want to create an extension that needs to do some work in the background, a good example would be an RSS feed. Now you'll probably want your extension to check every now and then to see if anything new has been added to the feed and alert the user that new content is available.
This is quite easy to accomplish.
In your manifest.json file add the background permission:
Code: Select all
Now you simply add your code, which you want to run in the background, in to a new file called background.js "background": {
"scripts": ["background.js"]
},
Here's an example background.js file which updates the extension badge text every second:
Code: Select all
That is all you needvar i = 0;
window.setInterval(function () {
chrome.browserAction.setBadgeText({ text: String(i) });
i = i + 1;
}, 1000);
Happy coding