Bookmarks.search() does not work as expected

According to https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/search i can search bookmark tree nodes with a either a string or a query. According to the description this query can be a url or a title. But at least searching by title does not return any search results.

For example, if there is a folder inside the bookmark tree nodes with the title “test” and i initiate a search with

var searching = browser.bookmarks.search({title: "test"});

The result is empty. However if i use

var searching = browser.bookmarks.search({url: "https://someurl.com"});

this works as expected and i get the as return the needed bookmark node with all details.

In my opinion this is a huge bug which needs to be fixed, because there is no other way to find folders, since folders didn’t have a url to search for.

You should file a bug report on https://bugzilla.mozilla.org/home

What workaround are you currently using?

Currently I have not found any workaround. That’s why I’m stuck a little bit with AddOn development.

Works for me in Firefox 84.0 (64-Bit) in Manjaro Linux.

  1. Run the attached test extesion with “web-ext run”
  2. Create a new bookmark folder named “test”
  3. Click on the browser action
    => bookmark name and type are logged in the console

What version are you using?

bookmarkfolders.zip (4.2 KB)

I upgraded some minutes ago to version 84. I will try your example tomorrow.

If that’s not too much work for you, can you please try to make the same test with chrome.bookmarks.search()?

Personally I prefer this over the Firefox specific variant, because my AddOn should run also with Chromium derivatives.

Also works with chrome.bookmarks.search(), as long as you use a callback instead of a promise.
Can you upload your code?

The Code is currently in Github. You will find example code at https://github.com/Offerel/SyncMarks-Extension/blob/dev/scripts/background.js.

Currently I have removed the part, where i search first the parent folder. But the default part of the switch should look like:

chrome.bookmarks.search({title: bArrayT[index].fdID}, function(removePFolder) {
	if(removePFolder[0].id.length != null) {
		chrome.bookmarks.search({bArrayT[index].bmURL}, function(removeMark) {
			chrome.bookmarks.remove(removeMark[0].id, function(remove) {
				chrome.bookmarks.onRemoved.addListener(onRemovedCheck);
			});
		});
	}
});

But in my tests, removePFolder was always empty or better, does not have any results. The object bArrayT holds my bookmark data, where fdID has the name of the parentfolder.

Currently i didnt search for the parentfolder, with the result that some of the bookmarks are not removed by the function (because im not at the right folder). I hope this makes sense for you. This is my first AddOn and im not very experienced in creating browser AddOns.

I have no idea if this is fixed in version 84, but i can confirm, that searching a folder by title/name is working now in my AddOn. I have no idea, why it wasn’t working before.

Then i can now rebuild the code for detecting the right folder. Many thx for your help.

I think i got the problem again, but only with the standard folders like unfiled_____ and menu________. Thats why, this fails:

chrome.bookmarks.search({title: "Weitere Lesezeichen"}, function(test) {
    console.log(test);
});

I don’t know if i can call this a bug, since all manual created folders are ok. I can workaround this, by only searching manual created folders.

As a workaround, you can get all bookmarks and then iterate over them.

Yes thats a nice idea. Since standard folders are always there and have always the same id, i exclude them from the search. It works so far.