How to export Android Chrome tabs to an HTML file in Linux (as of February 2023)

post by Adam Scherlis (adam-scherlis) · 2023-02-02T02:03:55.934Z · LW · GW · 3 comments

This is a link post for https://adam.scherlis.com/2023/02/01/how-to-export-android-chrome-tabs-to-an-html-file-in-linux-as-of-february-2023/

Contents

3 comments

Let's say you have a few million tabs open in your mobile Chrome browser, because you never close anything, but now your browser is getting slow and laggy. You want to stick the URLs of those tabs somewhere for safekeeping so that you can close them all.

There's a lot of advice on doing this on the Internet, most of which doesn't work.

Here's a method that does work. It's a bit of a hack, but gives good results:

  if (text.length > 100) {
   text = text.substring(0, 100) + '\u2026';
 }
import re

# Put the actual path to the input file here:
INPUT_FILE = '/home/blah/blah/my_better_tabs_file'
# Put the desired path to the output file here:
OUTPUT_FILE = '/home/blah/blah/phone_tabs_list.html'

with open(TABSFILE) as f:
    lines = f.readlines()

prefix = """<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My Phone Tabs</title>
  </head>
  <body>"""
outlines = [prefix]

for line in lines:
    name_match = re.match(r'<div class="name">(.*)</div>\n', line)
    url_match = re.match(r'<div class="url">(.*)</div></div>\n', line)
    if name_match:
        name = name_match.group(1)
        outlines.append(f'<br/><br/><b>{name}</b>\n')
    elif url_match:
        url = url_match.group(1)
        outlines.append(f'<br/><a href="{url}">{url}</a>\n')
    elif 'class="name"' in line or 'class="url"' in line:
        raise ValueError(f'Could not parse line:\n{line}')

suffix = """  </body>
</html>"""
outlines.append(suffix)

with open(OUTPUT_FILE, 'w') as f:
     f.writelines(outlines)

3 comments

Comments sorted by top scores.

comment by lise · 2023-02-02T23:22:26.876Z · LW(p) · GW(p)

Let's say you have a few million tabs open in your mobile Chrome browser, because you never close anything, but now your browser is getting slow and laggy.

Another fix for this specifically is to use Firefox onn Android, which does something like a suspend on inactive tabs. In my experience this completely fixes the "slow and laggy" aspect even with hundreds of suspended tabs.

Of course then you don't have a list of all your tabs, which is a useful resource you might want to create anyway.

Replies from: adam-scherlis
comment by Adam Scherlis (adam-scherlis) · 2023-02-03T01:44:53.053Z · LW(p) · GW(p)

Chrome actually stays pretty responsive in most circumstances (I think it does a similar thing with inactive tabs), with the crucial exception of the part of the UI that shows you all your open tabs in a scrollable list. It also gets slower to start up.

comment by wolajacy · 2023-07-03T10:43:39.095Z · LW(p) · GW(p)

FYI, in ther answer you linked to, there is another, way easier way of doing it (& it worked for me):

tl;dr:

  • have the Android command line tools installed on a development machine, and USB debugging enabled on your device. The device does not need to be rooted
  • adb forward tcp:9222 localabstract:chrome_devtools_remote
  • wget -O tabs.json http://localhost:9222/json/list