Reputation: 34632
I am trying to utilize the Google Bookmarks API for Chrome Extensions (this is not the Google Bookmarks API as in http://www.google.com/bookmarks/, but rather Chrome Bookmarks API).
Anyway, I just tried a simple example which I have the background.html and the manifest.json listed below. However, I am not getting the alert dialog box. I am not getting this problem if I switch to using tab events. What am I doing wrong?
manifest.json
{
"name": "Google Bookmark Integration",
"version": "1.0",
"description": "Integrates Chrome bookmarks with Google Bookmarks.",
"icons": { "128": "images/bookmark.ico" },
"background_page": "background.html",
"permissions": [
"bookmarks",
"http://*.google.com/bookmarks/*"
]
}
background.html
<script>
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
console.log("Bookmark Created");
});
</script>
Upvotes: 2
Views: 1321
Reputation: 11
If you want to see the console.log
of the background script, then you need to go to chrome://extensions/
and click on Inspect
views service worker and look for the message there.
Upvotes: 1
Reputation: 34632
To answer my own question, the problem here was that, not only do the permissions need to be set to "bookmarks" but they also need to be set to "tabs". Once I did this, the plug-in then recognized adding and removing bookmarks.
Very counterintuitive, but this is the solution.
Upvotes: 1
Reputation: 13236
JavaScript is dynamically typed and function definitions shouldn't have type names. Instead of (string id, BookmarkTreeNode bookmark), you need to write just (id, bookmark). Your background.html should be:
<script>
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
alert("Dialog Box");
});
</script>
In addition, apparently Chrome has limited support for alert() inside extensions. (It worked for me in this particular case, but I've now found other cases where it doesn't.) Try console.log() instead. The Chrome Extensions documentation page on "debugging" has instructions for how to open the Developer Tools / JavaScript console for the background.html page, which you'll need to do.
Upvotes: 1