Prevent event listener from been execute in Google Chrome Extension

476 views
Skip to first unread message

Viren Negi

unread,
Oct 12, 2011, 6:08:05 AM10/12/11
to Chromium-extensions
I'm looking to build a Google Chrome Extension to sync all my
bookmarks across chrome.

and for that I have attach a listener event onCreated

chrome.bookmarks.onCreated.addListener(function(id, bookmark) {

console.log("Hey bookmark created " + id)

});
Now the idea is when the User create a Bookmark the onCreated Event
Listener(Listed above) would sent an json data in ajax request to the
server stating that bookmark is created.

Now , If the server return a json data stating that new bookmark is to
be created on the browser

I dont need that the eventListener onCreated to be execute.

Basically the Idea is that the eventListener should trigger only if
the bookmarks is created manually by User and not when created
programmatically .

the above event listener should not get called when I create a
bookmark using the following command.

chrome.bookmarks.create({
'parentId': '648','title': 'Google Folder'
})

Boris Smus

unread,
Oct 12, 2011, 12:50:24 PM10/12/11
to Viren Negi, Chromium-extensions
Hi Viren,

Have you tried doing removing your listener temporarily with .removeListener - something like

var myListener = function(...) {...};
chrome.bookmarks.onCreated.addListener(myListener);
// Remove temporarily
chrome.bookmarks.onCreated.removeListener(myListener);
// Add again...

Also, in case you don't know, Chrome has been shipping with built in bookmark syncing for a couple of years now: http://blog.chromium.org/2009/08/bookmarks-here-bookmarks-there.html

- Boris



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.




--
Ask your next question on Stack Overflow, using the google-chrome-extension tag.
Reply all
Reply to author
Forward
0 new messages