Requisites
- "modern" Chrome for Android or equivalent (Kiwi Browser...)
- USB debugging enabled on Android
- ADB tools on PC
- Patience
- PC with Chrome (optional)
How it works
tldr; get list of tabs from chrome_devtools_remote, format it into a bookmarks file, done.
Step 1: Poking into Chrome for Android
You may have noticed that the Android build for Chrome is a bit limited on what it can do. If you are a "power user", more commonly known as a digital hoarder or just a chaotic person, you may have multiple tabs open that you may want to save or export. But the only thing you can export are bookmarks. You should use bookmarks. But who does that?
Render embedded dvdsub subtitles
Chrome for Android and its derivatives expose their remote devtools endpoint through a localabstract unix socket, which you may see if you access /proc/net/unix. The easiest way to access this is through ADB, although you can use Chrome directly on PC by plugging the phone visiting chrome://inspect#devices
.
Make sure you have ADB working, that being, you can plug your phone and bang adb devices
on the terminal and see its serial pop up. If that is not working, search the web for troubleshooting. Once that is done, type adb forward tcp:9222 localabstract:chrome_devtools_remote
and press enter. Done, you can access your phone's Chrome devtools through localhost:9222
.
Step 2: Tab list
There are a lot of ways to get the tab. They all appear nicely if you connect your PC Chrome devtools onto the remote with the URL mentioned above. But scraping this page feels like an incorrect choice. Because it is. Just wget -o tabs.json http://localhost:9222/json/list
or visit the URL on your browser. Easy json with all the info, and a tad more. Feel free to explore the file.
Step 3: Convert json to bookmarks file
If you want to import your tabs into bookmarks, you probably dont' want to type them all manually into your bookmarks. After all, you could have done it without all the previous hassle. Chrome uses the "Netscape bookmark file" format. A 10 second look into the file reveals it's just a basic HTML file with specific syntax. It really is not that difficult unless you want to programatically customize the exported tabs into folders. That is left as an exercise for the reader.
I will be displaying a way of converting all of this at once (mostly) with unix commands (basically printf
, cat
and jq
) but this could be done in a similar way in other automated systems of whatever flavour you prefer. First of all, let's create the header of the file with printf
:
printf '<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">\n<TITLE>Bookmarks</TITLE>\n<H1>Bookmarks</H1>\n<DL><p>\n' > bookmarks-header.html
Make sure you use single quotes to provide the "template". Use the same reasoning to do the footer:
printf '</DL><p>\n' > bookmarks-footer.html
And now, you can format the tabs (tabs.json) into bookmarks using jq
, like this (while also writing the final file):
jq -r '.[] | "<DT><A HREF=\"\(.url)\">\(.title)</A></DT>"' tabs.json | cat bookmarks-header.html - bookmarks-footer.html > final-bookmarks.html
That is all. You can even compact it into a single enter press like this:
> final-bookmarks.html ; printf '<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">\n<TITLE>Bookmarks</TITLE>\n<H1>Bookmarks</H1>\n<DL><p>\n' >> final-bookmarks.html ; jq -r '.[] | "<DT><A HREF=\"\(.url)\">\(.title)</A></DT>"' tabs.json >> final-bookmarks.html ; printf '</DL><p>\n' >> final-bookmarks.html
You can now import the file on your browser (PC or Android). Congratulations on completing the first step for organizing your digital life!
-inoricat