2021-04-24 03:18:15 +00:00
#!/usr/bin/env bash
# Helper script to export browser history and bookmarks to a format ArchiveBox can ingest.
# Usage:
# curl -O 'https://raw.githubusercontent.com/ArchiveBox/ArchiveBox/dev/bin/export_browser_history.sh'
# bash export_browser_history.sh --chrome
# bash export_browser_history.sh --firefox
# bash export_browser_history.sh --safari
# ls
# chrome_history.json
# firefox_history.json
# firefox_bookmarks.json
# safari_history.json
2018-06-11 00:52:15 +00:00
2020-08-18 04:36:46 +00:00
OUTPUT_DIR = " $( pwd ) "
2019-01-11 11:53:34 +00:00
2018-06-11 00:52:15 +00:00
if [ [ " $1 " = = "--chrome" ] ] ; then
# Google Chrome / Chromium
if [ [ -e " $2 " ] ] ; then
2020-08-18 04:36:46 +00:00
cp " $2 " " $OUTPUT_DIR /chrome_history.db.tmp "
2018-06-11 00:52:15 +00:00
else
2019-02-19 08:37:03 +00:00
default = $( ls ~/Library/Application\ Support/Google/Chrome/Default/History)
2018-06-11 00:52:15 +00:00
echo " Defaulting to history db: $default "
echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
2020-08-18 04:36:46 +00:00
cp " $default " " $OUTPUT_DIR /chrome_history.db.tmp "
2018-06-11 00:52:15 +00:00
fi
2020-08-18 04:36:46 +00:00
sqlite3 " $OUTPUT_DIR /chrome_history.db.tmp " "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_time, 'description', title, 'href', url)) || \"]\" FROM urls;" > " $OUTPUT_DIR /chrome_history.json "
jq < " $( dirname " ${ 2 :- $default } " ) " /Bookmarks '.roots.other.children[] | {href: .url, description: .name, timestamp: .date_added}' > " $OUTPUT_DIR /chrome_bookmarks.json "
2021-04-24 03:18:15 +00:00
rm " $OUTPUT_DIR " /chrome_history.db.*
2018-06-11 00:52:15 +00:00
echo "Chrome history exported to:"
2021-04-24 03:18:15 +00:00
echo " $OUTPUT_DIR /chrome_history.json "
2018-06-11 00:52:15 +00:00
fi
if [ [ " $1 " = = "--firefox" ] ] ; then
# Firefox
if [ [ -e " $2 " ] ] ; then
2020-08-18 04:36:46 +00:00
cp " $2 " " $OUTPUT_DIR /firefox_history.db.tmp "
2018-06-11 00:52:15 +00:00
else
2019-02-19 08:37:03 +00:00
default = $( ls ~/Library/Application\ Support/Firefox/Profiles/*.default/places.sqlite)
2018-06-11 00:52:15 +00:00
echo " Defaulting to history db: $default "
echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
2020-08-18 04:36:46 +00:00
cp " $default " " $OUTPUT_DIR /firefox_history.db.tmp "
2018-06-11 00:52:15 +00:00
fi
2020-08-18 04:36:46 +00:00
sqlite3 " $OUTPUT_DIR /firefox_history.db.tmp " "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_date, 'description', title, 'href', url)) || \"]\" FROM moz_places;" > " $OUTPUT_DIR /firefox_history.json "
sqlite3 " $OUTPUT_DIR /firefox_history.db.tmp " "SELECT \"[\" || group_concat(json_object('timestamp', b.dateAdded, 'description', b.title, 'href', f.url)) || \"]\" FROM moz_bookmarks AS b JOIN moz_places AS f ON f.id = b.fk" > " $OUTPUT_DIR /firefox_bookmarks.json "
2021-04-24 03:18:15 +00:00
rm " $OUTPUT_DIR " /firefox_history.db.*
2018-06-11 00:52:15 +00:00
echo "Firefox history exported to:"
2021-04-24 03:18:15 +00:00
echo " $OUTPUT_DIR /firefox_history.json "
echo " $OUTPUT_DIR /firefox_bookmarks.json "
2018-06-11 00:52:15 +00:00
fi
2020-02-04 01:18:18 +00:00
if [ [ " $1 " = = "--safari" ] ] ; then
# Safari
if [ [ -e " $2 " ] ] ; then
2020-08-18 04:36:46 +00:00
cp " $2 " " $OUTPUT_DIR /safari_history.db.tmp "
2020-02-04 01:18:18 +00:00
else
default = "~/Library/Safari/History.db"
echo " Defaulting to history db: $default "
echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
2020-08-18 04:36:46 +00:00
cp " $default " " $OUTPUT_DIR /safari_history.db.tmp "
2020-02-04 01:18:18 +00:00
fi
2020-08-18 04:36:46 +00:00
sqlite3 " $OUTPUT_DIR /safari_history.db.tmp " "select url from history_items" > " $OUTPUT_DIR /safari_history.json "
2021-04-24 03:18:15 +00:00
rm " $OUTPUT_DIR " /safari_history.db.*
2020-02-04 01:18:18 +00:00
echo "Safari history exported to:"
2021-04-24 03:18:15 +00:00
echo " $OUTPUT_DIR /safari_history.json "
2020-02-04 01:18:18 +00:00
fi