Skip to content

agzam/browser-hist.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Search through the Browser history, in Emacs

Description

Browsers usually keep their history in a sqlite database, and it’s trivial to extract it. This package allows you to search through your browser history by URL and the Page Title.

Requirements

For Emacs versions prior 29, install sqlite.el

Emacs 29 has built-in support for sqlite, but any prior versions of Emacs need sqlite.el installed.

Note that if you add the package to your config and at some point do switch to Emacs 29, you’d have to remove it because Emacs 29 also includes a package with the same exact name.

It’s probably possible to wrap the package declaration in a check like:

(unless (and (fboundp 'sqlite-available-p)
             (sqlite-available-p))
  (package! sqlite))

But I’m not sure if that would properly work, and of course, it all depends on the package manager you’re using.

How to use it

1. Install the package using your favorite package manager.

e.g., for Doom:

packages.el:

(package! browser-hist :recipe (:host github :repo "agzam/browser-hist.el"))

;; For Emacs versions prior 29
(package! sqlite)

config.el:

;; For Emacs versions prior 29
(use-package! sqlite)

(use-package! browser-hist
  :init
  (require 'embark) ; load Embark before the command (if you're using it)
  :config
  (setq browser-hist-default-browser 'firefox)
  :commands (browser-hist-search))

2. Set the mandatory variable(s)

  • browser-hist-default-browser - set this var, the package doesn’t know yet how to resolve the default browser automatically

    example:

    (setq browser-hist-default-browser 'chrome)
        
  • Optionally, you may have to set browser-hist-db-paths. The package should resolve these paths automatically. But if it fails you, the first thing I would suggest is to check the values that var holds and make sure that the path to the DB is correct. You can set the paths explicitly, like so:
    (setq browser-hist-db-paths
          '((chrome . "$HOME/Library/Application Support/Google/Chrome/Default/History")
            (brave . "$HOME/Library/Application Support/BraveSoftware/Brave-Browser/Default/History")
            (firefox . "$HOME/Library/Application Support/Firefox/Profiles/*.default-release/places.sqlite")))
        

    You may even ignore the browsers you don’t use; right now the package works only with a single browser. I’m considering adding data retrieval for multiple browsers at some point.

  • Set minimum number of chars (optional)
    (setq browser-hist-minimum-query-length 2) ; default is 3
        
  • Set cache invalidation (optional)

    The browser history database needs to be copied every time. Depending on its size, it may take a second or more. If you don’t necessarily care for the most recent items in the history and only want to occasionally search for older items, you may want to set the cache timeout value. This way, the search dialog will open faster, at the expense of missing some of the most recent items. In my experience, however, this variable almost always can remain at 0 and not affect performance at all.

    (setq browser-hist-cache-timeout 60) ; default is 0
        

    The main search command can be called with a prefix argument that forces it to ignore cached DB and copy it anew.

Important note for Safari (Mac) users

Make sure that Emacs has Full Disk Access. Otherwise, the system won’t even let it touch the file.

Go to Preferences -> Privacy & Security -> Full Disk Access, and add Emacs. Make sure Emacs has access to the folder, run M-x find-file and navigate to $HOME/Library/Safari/ - it should let you.

3. Try it

There’s only one command right now, browser-hist-search, try running it and see if it works. Let me know if it doesn’t.

FAQ

What’s the point? Why even have this if you can do it in the browser?

  • It’s convenient and a bit faster to bind the command to a key.
  • And then, using an Embark Action you can open the link in EWW, in XWidget, or any other browser (not necessarily the history origin one).
  • You can also narrow the search and export the results into a separate buffer using Embark Collect.
  • It opens some other possibilities like sending a link to a browser but forcing it to find the tab (if there’s an open one already, e.g., why open another GMail tab?) That could be done using Applescript on Mac, xdotool or TabFS on Linux.
  • Or maybe open the link in a private tab of a chosen browser.
  • I’m also hoping at some point to collect data from multiple browsers.

About

Search through browser history, in Emacs

Topics

Resources

License

Stars

Watchers

Forks