The bookmarks.removeTree()
method recursively removes a bookmark folder and all of its contents.
Warning: If your extension attempts to remove a bookmark tree from the bookmarks tree root node, the call will raise an error with the message: "The bookmark root cannot be modified" and the bookmark won't be removed.
This is an asynchronous function that returns a Promise
.
var removingTree = browser.bookmarks.removeTree( id // string )
id
string
specifying the ID of the folder node to be deleted along with its descendants.A Promise
that will be fulfilled with no arguments when the tree has been removed.
If the node corresponding to the id
parameter can't be found, the promise is rejected with an error message.
This example locates a bookmark folder named "MDN" and deletes it along with all of its contents.
function onRemoved() { console.log("bookmark item removed!"); } function onRejected(error) { console.log(`An error: ${error}`); } function removeMDN(searchResults) { if (searchResults.length) { var removing = browser.bookmarks.removeTree(searchResults[0].id); removing.then(onRemoved, onRejected); } } var searchingBookmarks = browser.bookmarks.search({ title: "MDN" }); searchingBookmarks.then(removeMDN, onRejected);
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
removeTree |
Yes |
15 |
47 |
? |
Yes |
No |
? |
? |
No |
? |
? |
? |
Note: This API is based on Chromium's chrome.bookmarks
API. This documentation is derived from bookmarks.json
in the Chromium code.
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/bookmarks/removeTree