Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:57:29+00:00 2026-06-18T09:57:29+00:00

I’d like to be able to return an array of all a users bookmark

  • 0

I’d like to be able to return an array of all a users bookmark folders from the root folder at any point in the tree.

This is the closest I’ve come which returns nothing of RESULT_TYPE_FOLDER:

function find_folders()
{
  var history = Cc["@mozilla.org/browser/nav-history-service;1"]
     .getService(Ci.nsINavHistoryService);

  var query = history.getNewQuery();
  var options = history.getNewQueryOptions();

  // Query users bookmarks, not history
  options.queryType = options.QUERY_TYPE_BOOKMARKS;

  // Execute the search and store results
  var result = history.executeQuery(query, options);

  // Open the root containerNode and open it
  var resultContainerNode = result.root;

  // OPEN resultContainerNode
  resultContainerNode.containerOpen = true;
  var folders = [];

  // Search results are now child items of this container?
  for (var i=0; i < resultContainerNode.childCount; ++i) {
    var childNode = resultContainerNode.getChild(i);

    if(childNode.type === childNode.RESULT_TYPE_FOLDER)
    {
      folders.push(childNode);
    }
  }

  // CLOSE resultContainerNode
  resultContainerNode.containerOpen = false;

  return folders;
};

find_folders();

If I remove this result type checking I get lots of URIs, some RESULT_TYPE_QUERYs, but no RESULT_TYPE_FOLDER:

childNode.type: 0
childNode.type: RESULT_TYPE_QUERY
childNode.title: Most Visited
childNode.type: 0
childNode.type: 0
childNode.type: 0
childNode.type: 0
childNode.type: 0
childNode.type: 0
childNode.type: 0
childNode.type: 0
childNode.type: 0
childNode.type: 0
childNode.type: RESULT_TYPE_QUERY
childNode.title: History

The documentation here: https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavHistoryQueryOptions#Query_type_constants
suggests you can set:

excludeItems boolean This option excludes all URIs and separators from
a bookmarks query. This would be used if you just wanted a list of
bookmark folders and queries (such as the left pane of the places
page). Ignored for queries over history. Defaults to false.

But setting this causes the query to return no results:

function find_folders()
{
  var history = Cc["@mozilla.org/browser/nav-history-service;1"]
     .getService(Ci.nsINavHistoryService);

  var query = history.getNewQuery();
  var options = history.getNewQueryOptions();

  options.queryType = options.QUERY_TYPE_BOOKMARKS;
  options.excludeItems = true; // Exclude everything that isn't a folder?
  // Execute the search and store results
  var result = history.executeQuery(query, options);

  // Open the root containerNode and open it
  var resultContainerNode = result.root;

  // OPEN resultContainerNode
  resultContainerNode.containerOpen = true;
  var folders = [];

  // Search results are now child items of this container?
  for (var i=0; i < resultContainerNode.childCount; ++i) {
    var childNode = resultContainerNode.getChild(i);
    folders.push(childNode);
  }

  // CLOSE resultContainerNode
  resultContainerNode.containerOpen = false;

  return folders;
};

find_folders(); // Returns nothing :C
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:57:30+00:00Added an answer on June 18, 2026 at 9:57 am

    Okay looks like I’ve run into a few bugs and limitations in the Firefox Places query interface.

    1 – (bug?) setting query.setFolders([folder_array], 1) with the second paramater (folder count) to anything other than 1 causes no results. Setting it to 1 will only search the first folder from your array.

    2 – (limitation) excludeItems works only if you specify folders to search into which isn’t helpful :C

    3 – (limitation/bug?) query.setSearchTerm(term) seems to not match folder names so I had to manually check them against the search term :Q__

    Sketchy workaround solution is to create the array of folders to search and then search separately through each one, concatenating the results, like so:

    bookmarkr_utilities.find_folders = function(search_term)
    {
      bookmarkr_utilities.debug_log("find_folders()");
      bookmarkr_utilities.folders = [];
    
    
      var folders = [   bookmarkr_utilities.bmsvc_service().toolbarFolder
                      , bookmarkr_utilities.bmsvc_service().bookmarksMenuFolder
                      , bookmarkr_utilities.bmsvc_service().unfiledBookmarksFolder   ];
    
    
      for (var i = 0; i < folders.length; i++) 
      {
        bookmarkr_utilities.folders = bookmarkr_utilities.folders.concat(bookmarkr_utilities.find_inside_folder(search_term, folders[i]));
      }
    
      return bookmarkr_utilities.folders;
    };
    

    Helper function to actually run the search:

    bookmarkr_utilities.find_inside_folder = function(search_term, search_folder)
    {
      var history = Cc["@mozilla.org/browser/nav-history-service;1"]
         .getService(Ci.nsINavHistoryService);
    
      var result_folders = [];
    
      var query = history.getNewQuery();
    
      query.setFolders([search_folder], 1);
    
      var options = history.getNewQueryOptions();
    
      options.excludeItems = true; // exclude everything except folders
                                   // only works when folders are set
    
      // Execute the search and store results
      var result = history.executeQuery(query, options);
    
      // Open the root containerNode and open it
      var resultContainerNode = result.root;
      resultContainerNode.containerOpen = true;
    
      // Search results are now child items of this container?
      bookmarkr_utilities.debug_log("resultContainerNode.childCount: " + resultContainerNode.childCount);
      for (var i=0; i < resultContainerNode.childCount; ++i) {
        var childNode = resultContainerNode.getChild(i);
    
        if(childNode.type === childNode.RESULT_TYPE_FOLDER)
        {
          // HACK HACK HACK
          if(search_term)
          {
            if(childNode.title.toLowerCase() == search_term.toLowerCase())
              result_folders.push(childNode);
          }
          // END HACK HACK HACK OH GOD
          else
          {
            result_folders.push(childNode);
          }
        }
      }
    
      // Close container
      resultContainerNode.containerOpen = false;
    
      return result_folders;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.