Search code examples
google-chromegoogle-chrome-extensionbookmarks

Accessing a new bookmarks' URL within a Chrome Extension


I've made a few Chrome extensions already but this has really stumped me.

I have an idea for an extension that adds additional information to a bookmark's URL when a user bookmarks a page. The simplest way to do this would using a hash tag on the end.

E.g. a.site.com/page/2/#extrainfohere

So in effect I want the extension to listen for when a user bookmarks a page, calculate some information e.g. scroll position, and append this to bookmarks URL as it is saved.

Does anyone have any clue is there is a way to do this? Any hook in Chrome that could be used to extend the default bookmarking action?

Thanks in advance


Solution

  • I think you need something like this:

    chrome.bookmarks.onCreated.addListener(
    function(id, bookmark) {        
        var new_url = bookmark.url + "#somedata";
        chrome.bookmarks.update(id, {url : new_url}, function {});
    });