Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ninmonkey/8655e06a3f985aece507c91da40ecfd9 to your computer and use it in GitHub Desktop.
Save ninmonkey/8655e06a3f985aece507c91da40ecfd9 to your computer and use it in GitHub Desktop.
Firefox Bookmarks using dynamic sql places queries.md

Source.md

Bookmarks that dynamically Query your bookmarks

This works on Firefox version 87 on 2021-04-04

  1. Create a new bookmark
  2. Set location to the query below
  3. Restart Firefox (it doesn't show query results until you restart)

This appears to be undocumented, (the docs don't seem to exist anymore) So expect this to break. (Another change is: bookmarks now export as .json and .jsonlz4 instead of sqlite3)

To find your places.sqlite using Powershell:

Get-ChildItem -Path $Env:AppData\Mozilla\Firefox places.sqlite -Recurse
| Sort-Object LastWriteTime -Descending
| Foreach-Object FullName

Main Docs

Examples

tag: Cat

name:  tag → Cat
query: place:sort=12&tag=cat&maxResults=30&excludeQueries=1
sortby: most recently added

Time: Visit during Today Order By VisitCount

  • queryType 0 = history, 1 = bookmarks
  • timeRef 1 = relative today at 00:00:00
  • sort
    • 2 = Title Desc
    • 4 = Date Desc
    • 8 = VisitCount Desc
name:   Today → VisitCount
tags:   dial, Dial DynamicBookmark, Query, speedDial
query:  place:queryType=0&sort=8&maxResults=30&beginTimeRef=1&beginTime=0
sortby: VisitCount Desc

Time: Visit during Today Order By TimeAdded

name:   Today → VisitOrder
tags:   dial, Dial DynamicBookmark, Query, speedDial
query:  place:queryType=0&sort=4&maxResults=30&beginTimeRef=1&beginTime=0
sortby: VisitOrder Desc

Time: Visit url Reddit.com during Today Order By VisitTime

name:   Today → 'Reddit.com' VisitOrder
tags:   dial, Dial DynamicBookmark, Query, speedDial
query:  place:queryType=0&sort=4&maxResults=30&beginTimeRef=1&beginTime=0&domain=reddit.com
sortby: VisitOrder Desc

Time: Visit url docs.microsoft.com Order By VisitTime

name:   Today → Docs.Microsoft.com | Visit
name:   Today → Docs.Microsoft.com' VisitOrder
tags:   dial, Dial DynamicBookmark, Query, speedDial
query:  place:queryType=0&sort=4&maxResults=30&beginTimeRef=1&beginTime=0&domain=docs.microsoft.com
sortby: VisitOrder Desc

Time: Visit url gist.github.com Order By VisitTime

name:   Today → Gist | Visit
tags:   dial, Dial DynamicBookmark, Query, speedDial
query:  place:queryType=0&sort=4&maxResults=30&beginTimeRef=1&beginTime=0&domain=gist.github.com
sortby: VisitOrder Desc

Time: Visit url github.com but ! gist Order By VisitTime

  • DomainIsHost bool means domain must exactly match
name:   Today → Github | Visit
tags:   dial, Dial DynamicBookmark, Query, speedDial
query:  place:queryType=0&sort=4&maxResults=30&beginTimeRef=1&beginTime=0&domain=github.com&domainIsHost=1
sortby: VisitOrder Desc

[broken] Time: Bookmark during Last 1Weeks Order By VisitTime

(24hour * 7days) => to microseconds: 6.048e+11 -> 604800000000 6.048e+11

  • queryType 0 = history, 1 = bookmarks
  • timeRef 1 = relative today
  • beginTime = 604800000000
  • sort
    • 12 = DateAdded Desc
name:   Last 7 Days → Bookmarked
tags:   dial, Dial DynamicBookmark, Query, speedDial
query:  place:queryType=1&sort=12&maxResults=40&beginTimeRef=1&beginTime=604800000000
sortby: VisitCount Desc

Query Enum Values

Misc

Parameter Type Description
terms string Search terms
tag string (Docs were empty). Can you chain tags in the query string?
minVisits long Filters results based on the minimum number of visits.
Specify -1 (the default) to return all results, or any other number
to only include results with a visit count > value
maxVisits long Filters results based on the maximum number of visits.
Specify -1 (the default) to return all results, or any other number
to only include results with a visit count < value
onlyBookmarked bool Only bookmarks
uri string The URI to match.
uriIsPrefix bool If false, the uri must be an exact match; this is the default.
If true, any entry that begins with the specified URI is considered a match.
domain string Query for items matching this host or domain name. See domainIsHost for more information.
domainIsHost bool If true, domain must be an exact match. Otherwise, anything that ends in domain is considered a match.
!annotation bool Indicates whether to include or reject items matching the annotation specified by annotation.
If true, items that don't have the specified annotation are rejected.
!tags (Docs were empty). Maybe require zero tags, or, query for a tag that is not set

Enum: QUERY_TYPE_*

queryType is an unsigned short. The type of search to use when querying the database. This attribute is only honored by query nodes. It's ignored for simple folder queries.

Type Value
QUERY_TYPE_HISTORY 0
QUERY_TYPE_BOOKMARKS 1
QUERY_TYPE_UNIFIED 2 (NYI: #378798)

Enum: TIME_RELATIVE_* - query param beginTimeRef

used for query parameter beginTimeRef

Type Value
TIME_RELATIVE_EPOCH 0
TIME_RELATIVE_TODAY 1
TIME_RELATIVE_NOW 2

Other time parameters

Parameter Description
beginTime The time, in microseconds of the earliest result to return.
beginTimeRef enum TIME_RELATIVE_*
endTime The time, in microseconds, of the latest result to return.
endTimeRef enum TIME_RELATIVE_*

Enum: GROUP_BY_*

Type Value
GROUP_BY_DAY 0
GROUP_BY_HOST 1
GROUP_BY_DOMAIN 2
GROUP_BY_FOLDER 3

Enum: SORT_BY_*

Type Value Description
SORT_BY_NONE 0
SORT_BY_TITLE_ASCENDING 1
SORT_BY_TITLE_DESCENDING 2
SORT_BY_DATE_ASCENDING 3
SORT_BY_DATE_DESCENDING 4
SORT_BY_URI_ASCENDING 5
SORT_BY_URI_DESCENDING 6
SORT_BY_VISITCOUNT_ASCENDING 7
SORT_BY_VISITCOUNT_DESCENDING 8
SORT_BY_KEYWORD_ASCENDING 9
SORT_BY_KEYWORD_DESCENDING 10
SORT_BY_DATEADDED_ASCENDING 11
SORT_BY_DATEADDED_DESCENDING 12
SORT_BY_LASTMODIFIED_ASCENDING 13
SORT_BY_LASTMODIFIED_DESCENDING 14
SORT_BY_ANNOTATION_ASCENDING 15
SORT_BY_ANNOTATION_DESCENDING 16

Enum: RESULTS_AS_*

Type Value
RESULTS_AS_URI 0
RESULTS_AS_VISIT 1
RESULTS_AS_FULL_VISIT 2 (Removed: #320831)

Notes:

  • results_as_url: This is the default, and returns one result node of type RESULT_TYPE_URI for each URI that matches the query. The visit date for each node will be the last visit date for that URL.
  • RESULTS_AS_VISIT: This option returns one entry for each time a page was visited matching the given query. The result may contain duplicate entries for URLs, each with a different date. The nodes are of type RESULT_TYPE_VISIT, and provide a session ID for each visit. This session ID is the same for all pages that were reached by clicking links. A new session starts when the user types a new URL or follows a bookmark (XXX link to more details about what constitutes a session).

Attributes / "Query Operators"

Attribute Type Name
OR Logical OR
unsigned long maxResults
unsigned short queryType
unsigned short sortingMode
AUTF8String sortingAnnotation
unsigned short resultType
boolean excludeItems
boolean excludeQueries
boolean excludeReadOnlyFolders
boolean expandQueries
boolean includeHidden
boolean showSessions
nyi? applyOptionsToContainers

Notes

  • maxResults: unsigned long: The maximum number of results to return. This doesn't work when sorting by title. 0 means return all
  • includeHidden: bool: If true, items that would normally be hidden in a history query (such as the content of iframes as well as images) are included in the results. This is false by default.
  • expandQueries: bool: If true, place URIs appear as containers in the results, with the contents filled in from the stored query. This doesn't do anything if excludeQueries is true. The default is false, which causes place URIs to appear as normal items.

Quick Reference for Query String Values:

queryType = <int>

queryType is an unsigned short. The type of search to use when querying the database. This attribute is only honored by query nodes. It's ignored for simple folder queries.

int Description
0 History
1 Bookmarks
2 Both (Nyi)

type = <int>

type: unsigned short, the type of results to return.

Value Description
0 Results as URI ("URI" results, one for each URI visited in the range).
1 Results as visit ("visit" results, with one for each time a page was visited
This will often give you multiple results for one URI).
2 Results as full visits (like "visit", but returns all attributes for each result)
3 Results as date query (returns results for given date range)
4 Results as site query (returns last visit for each url in the given host)
5 Results as date+site query (returns list of hosts visited in the given period)
6 Results as tag query (returns list of bookmarks with the given tag)
7 Results as tag container (returns bookmarks with given tag; for same uri uses last modified. folder=tag_folder_id must be present in the query

sort = <int>

sort: unsigned short, sort order

Value Description
0 Natural bookmark order
1 Sort by title, A-Z
2 Sort by title, Z-A
3 Sort by visit date, most recent last
4 Sort by visit date, most recent first
5 Sort by uri, A-Z
6 Sort by uri, Z-A
7 Sort by visit count, ascending
8 Sort by visit count, descending
9 Sort by keyword, A-Z
10 Sort by keyword, Z-A
11 Sort by date added, most recent last
12 Sort by date added, most recent first
13 Sort by last modified date, most recent last
14 Sort by last modified date, most recent first
17 Sort by tags, ascending
18 Sort by tags, descending
19 Sort by annotation, ascending
20 Sort by annotation, descending

# Maybe Related, Archived, Docs

- <https://web.archive.org/web/20190929202307/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Places_query_URIs>
- <https://web.archive.org/web/20190929203327/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places>
- <https://web.archive.org/web/20190930123750/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Using_the_Places_keywords_API>
- <https://web.archive.org/web/20191004045704/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Using_the_Places_history_service>
- <https://web.archive.org/web/20191004145824/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Querying>
- <https://web.archive.org/web/20191004172423/https://developer.mozilla.org/en-US/docs/Mozilla/Displaying_Place_information_using_views>
- <https://web.archive.org/web/20191006174624/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Places_utilities_for_JavaScript>
- <https://web.archive.org/web/20191007005101/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Manipulating_bookmarks_using_Places>
- <https://web.archive.org/web/20191008024821/https://developer.mozilla.org/en-US/docs/Mozilla/Displaying_Place_information_using_views>
- <https://web.archive.org/web/20191009102559/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Retrieving_part_of_the_bookmarks_tree>
- <https://web.archive.org/web/20200621121524/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/Places_Developer_Guide>
- <https://web.archive.org/web/20210121193337/https://developer.mozilla.org/en-US/docs/Mozilla/Tech/Places/places.sqlite_Database_Troubleshooting>

ITER2

  • sort12: most recently added
  • queryType=
place:folder=BOOKMARKS_MENU&
folder=UNFILED_BOOKMARKS&
folder=TOOLBAR&
sort=12&
tag=todo_2021-03&
maxResults=30&
excludeQueries=1

ITER3

Currently returns identical results as ITER2

  • sort12: most recently added
  • queryType=
place:
sort=12&
tag=todo_2021-03&
maxResults=30&
excludeQueries=1

// joined
place:sort=12&tag=todo_2021-03&maxResults=30&excludeQueries=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment