Background Tasks

Helpful tutorials about how to create Chrome Extensions
1 post Page 1 of 1
Contributors
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Background Tasks
CodenStuff
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:
Code: Select all
  "background": {
      "scripts": ["background.js"]
  },
Now you simply add your code, which you want to run in the background, in to a new file called background.js

Here's an example background.js file which updates the extension badge text every second:
Code: Select all
var i = 0;
window.setInterval(function () {
    chrome.browserAction.setBadgeText({ text: String(i) });
    i = i + 1;
}, 1000);
That is all you need

Happy coding :)
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
1 post Page 1 of 1
Return to “Tutorials”