Basics of bookmarks api ?

324 views
Skip to first unread message

CqN on cr-48 devchannel 0.12.397.0

unread,
Jun 9, 2011, 12:55:02 PM6/9/11
to Chromium-extensions
I tried this in an ext in the popup.html in cr-48 [has
permissions:bookmarks inlcuded in the manifest], but getting errors.

Suppose I want to create a new folder named/titled 'XYZ' in one of
the existing folders 'Other bookmarks', and then add a link 'abc' with
link title 'pqr':

chrome.bookmarks.create( {'parentId':'Other bookmarks',
'title':'XYZ' },
function (newFolder){alert('Created new folder'
+ newFolder.title);} );
chrome.bookmarks.create({'parentId':'XYZ', 'title':'pqr',
'url':'abc'});


In the above, on callback, newFolder appears to be undefined. What is
wrong in the syntax above?

B. Instead of creating the new folder XYZ in an existing folder as
above, if XYZ is to be created on the folder bar itslef, what should
be the parameter in place 'Other bookmarks' in the first .create()?

CqN

Arne Roomann-Kurrik

unread,
Jun 20, 2011, 9:28:58 PM6/20/11
to CqN on cr-48 devchannel 0.12.397.0, Chromium-extensions
On Thu, Jun 9, 2011 at 9:55 AM, CqN on cr-48 devchannel 0.12.397.0 <chacko...@gmail.com> wrote:
I tried this in an ext in the popup.html in cr-48 [has
permissions:bookmarks inlcuded in the manifest], but getting errors.

Suppose I want to create a new folder named/titled 'XYZ'  in one of
the existing folders 'Other bookmarks', and then add a link 'abc' with
link title 'pqr':

chrome.bookmarks.create( {'parentId':'Other bookmarks',
'title':'XYZ' },
                     function (newFolder){alert('Created new folder'
+ newFolder.title);}  );
chrome.bookmarks.create({'parentId':'XYZ',  'title':'pqr',
'url':'abc'});


In the above, on callback, newFolder appears to be undefined.  What is
wrong in the syntax above?

parentId should be the ID of a node in the bookmarks tree, not the name of a folder.  You'll need to use chrome.bookmarks.getTree or chrome.bookmarks.search to find a parent node and get its ID.
 

B.  Instead of creating the new folder XYZ in an existing folder as
above, if XYZ is to be created on the folder bar itslef, what should
be the parameter in place 'Other bookmarks' in the first .create()?

Call chrome.bookmarks.getTree and iterate over the children of the root node to find the IDs of these folders.  

~Arne
 

CqN

--
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.


Reply all
Reply to author
Forward
0 new messages