How to see Tags for Bookmarks in Web-Extension?

Giovanni Meo giovannimeo at gmail.com
Sat Nov 18 16:40:17 UTC 2017


Hi Andrew,

thanks you very much for the prompt reply. I have found a workaround, i noticed
that the Bookmarks has a special folder with id "tags________" so getting that
subtree and then searching for the folder with title "<my tag>" solve my problem.

Thanks,
Giovanni

On 11/17/2017 07:54 PM, Andrew Swan wrote:
>
> There is not currently an API for accessing bookmarks tags.  There is a length
> discussion about creating such an API here:
> https://bugzilla.mozilla.org/show_bug.cgi?id=1225916
>
>
> On Fri, Nov 17, 2017 at 2:38 AM, Giovanni Meo <giovannimeo at gmail.com
> <mailto:giovannimeo at gmail.com>> wrote:
>
>     Hi folks,
>
>     i have an old SDK extension that was able to query the bookmarks by the
>     tag, using this piece of code:
>
>>     function loadFromBookMarks() {
>>         let { search, UNSORTED } = require("sdk/places/bookmarks");
>>
>>         // Multiple queries are OR'd
>>     together                                                                                                                                   
>>      
>>         search(
>>             [ { tags: ["commandfox"] } ]
>>         ).on("data", function (result) {
>>             if (result !== undefined) {
>>                 jsonText = JSON.stringify(result);
>>                 makeSearchCommand({name: result.title,
>>                                    description: "Command " + result.title,
>>                                    url:  result.url});
>>             }
>>         });
>>     }
>
>     Now i'm trying to port this to Web Extension, but seems like the search
>     API on bookmarks doesn't support tags, from the link:
>
>     https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search
>     <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search>
>
>     i see only these options:
>
>>     In This Article
>>     <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search#toc>
>>
>>
>>      1. Syntax
>>         <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search#Syntax>
>>
>>          1. Parameters
>>             <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search#Parameters>
>>          2. Return value
>>             <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search#Return_value>
>>      2. Browser compatibility
>>         <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search#Browser_compatibility>
>>      3. Example
>>         <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search#Example>
>>
>>          1. Example extensions
>>             <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/bookmarks/search#Example_extensions>
>>
>>     The *|bookmarks.search()|* function searches for bookmarks matching the
>>     given query.
>>
>>     This function throws an exception if any of the input parameters are
>>     invalid or are not of an appropriate type; look in the console
>>     <https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Debugging> for
>>     the error message. The exceptions don't have error IDs, and the messages
>>     themselves may change, so don't write code that tries to interpret them.
>>
>>     This is an asynchronous function that returns a |Promise
>>     <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>|.
>>
>>
>>         Syntax
>>
>>     var searching = browser.bookmarks.search(
>>       query                  // string or object
>>     )
>>
>>
>>           Parameters
>>
>>     |query|
>>         A |string|
>>         <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string>
>>         or |object|
>>         <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/object>
>>         describing the query to perform.
>>
>>         If |query| is a string, it consists of zero or more search terms.
>>         Search terms are space-delimited and may be enclosed in quotes to
>>         allow multiple-word phrases to be searched against. Each search term
>>         matches if it matches any substring in the bookmark's URL or title.
>>         Matching is case-insensitive. For a bookmark to match the query, all
>>         the query's search terms must match.
>>
>>         If |query| is an object, it has zero or more of the following 3
>>         properties: |query|, |title|, and |url|, which are described below.
>>         For a bookmark to match the query, all provided properties terms must
>>         match the specified values.
>>
>>         |query| Optional
>>             A |string|
>>             <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string>
>>             specifying one or more terms to match against; the format is
>>             identical to the string form of the |query| parameter. If this
>>             isn't a string, an exception is thrown.
>>         |url| Optional
>>             A |string|
>>             <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string>
>>             which must exactly match the bookmark's URL. Matching is
>>             case-insensitive, and trailing slashes are ignored.
>>
>>             If you pass an invalid URL here, the function will throw an
>>             exception.
>>
>>         |title| Optional
>>             A |string|
>>             <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string>
>>             This must exactly match the bookmark's title. Matching is
>>             case-sensitive.
>>
>
>     Any idea on how to achieve similar functionality?
>
>     Thanks in advance for any help you may provide,
>     Giovanni
>
>
>
>     _______________________________________________
>     Dev-addons mailing list
>     Dev-addons at mozilla.org <mailto:Dev-addons at mozilla.org>
>     https://mail.mozilla.org/listinfo/dev-addons
>     <https://mail.mozilla.org/listinfo/dev-addons>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/dev-addons/attachments/20171118/6c420370/attachment.html>


More information about the Dev-addons mailing list