Tuesday, April 10, 2012

How to debug Google Chrome background script?

I have very simple extension:
manifest.json
 {   "name": "historyCleaner",   "version": "0.1.1",   "manifest_version": 1,   "description": "This is my first Chrome extension",   "background": {     "scripts": ["cleaner.js"]   },   "permissions": [     "history"   ] } 
cleaner.js
 chrome.history.onVisited.addListener(function(HistoryItem result) {    console.log("it works!");   alert("it works!");  }); 
I've loaded it in Google Chrome, it is turned on and... it doesn't work. It doesn't log anything in console, it doesn't alert anything and what is worse, I can't find it in developers tools "Scripts" tab. How can I find why it doesn't work?

 Answer:

enter image description here
and also if your console.log("it works!"); does not show up, then that's meanchrome.history.onVisited is not fired yet.
ps: For function(HistoryItem result), you may want to change it tofunction(HistoryItem,result)

No comments:

Post a Comment