DEV Community

Marcin Piczkowski
Marcin Piczkowski

Posted on • Edited on

When you never close tabs on your mobile Chrome browser

Whenever I browse on my mobile I often open an interesting pages in Chrome and leave it for later. Usually the later never comes so I ended up with over 2500 open tabs in my mobile Chrome. Yes, it's not a typo !!!

Recently I wanted to do some cleanup. I was on my desktop and wanted to quickly order useful urls into some categories and bookmark for later or throw away at all if not needed anymore. I realised that there is no handy way of exporting all the open tabs from Chrome. On desktop version of Chrome there is a "Bookmark All Tabs" feature when you right-click any of the open tabs in browser, but this does not exist in mobile version.

I wanted to share with you an easy way to work-around this limitation if you're using an Android device.

You will need to install Android Dev Tools on your desktop and put your mobile device into Developer's Mode.

How to do it, step by step:

  1. Download an install Android Dev Tools.

We will need only adb application, but we will have to install the complete toolbox anyway. Personally, I found the easiest way to download an install the Android Studio, but you could also try the stand-alone sdk tool available from here if you scroll down.

When you have installed Android Studio on Mac, you will find adb in ~/Library/Android/sdk/platform-tools

Open this folder in bash.

  1. Put your Android phone in Developer's Mode and connect with a cable to your desktop. It's better to connect straight instead using some USB hubs, because sometimes the device cannot be discovered by adb. Here is an official instruction how to turn it on. Also, you may want to turn on MTP configuration in "Select USB Configuration" menu as described here, otherwise adb may not find your device.

When you completed the two steps above, you should be able to discover your Android device with adb. Try this from bash in folder where the adb binary is located:



./adb devices -l


Enter fullscreen mode Exit fullscreen mode

It should list your device, e.g:



List of devices attached
e8acbd80               device usb:336592896X product:OnePlus3 model:ONEPLUS_A3003 device:OnePlus3 transport_id:1


Enter fullscreen mode Exit fullscreen mode

Chrome mobile has a feature to expose remote debugger on tcp socket which you can access from your desktop. The so called "legacy" debugging workflow is described in Chrome developers documentation.
It is called "legacy" because now there is more fancy way of debugging mobile Chrome using Chrome Dev Tools.
For our purpose however the "legacy" way is more useful because we get access to a bare text interface in JSON format which gives easy way to extract open tabs URLs.

In short, you need to execute:



./adb forward tcp:9222 localabstract:chrome_devtools_remote


Enter fullscreen mode Exit fullscreen mode

Here is more info how it works. The above line makes adb forward any connections on localhost TCP port 9222 to the abstract socket named chrome_devtools_remote over USB.

Now, you should be able to browse Chrome remote API at: http://localhost:9222

The JSON with all open tabs info is at: http://localhost:9222/json/list

It looks like that:

JSON

If you have JQ tool installed you could parse this JSON, extract only URLs and save in txt file like that:



curl http://localhost:9222/json/list | jq .[].url > mobile.tabs.txt


Enter fullscreen mode Exit fullscreen mode

UPDATE:
(Thanks to Alete for this tip)

If there is more than one instance of chrome running on your Android and ./adb forward tcp:9222 localabstract:chrome_devtools_remote shows you the wrong one, you may need to find the process of the other instance like this:

First disable the undesired chrome app.
How to disable an app?
Find an app in applications.

Find Chrome in applications

Then hold an icon for long time until the popup menu show up.

Show popup menu

Then choose "App info" and you should see the screen like blow.

App info

Next, click "Disable" button.

Then on your PC in command line execute:



adb shell "cat /proc/net/unix" 


Enter fullscreen mode Exit fullscreen mode

Copy the output into a text editor and find chrome_devtools_remote in order to find the instance e.g.:
localabstract:chrome_devtools_remote_31723

Then



./adb forward tcp:9222 localabstract:chrome_devtools_remote_31723


Enter fullscreen mode Exit fullscreen mode

At the end you can enable the app which you disabled in previous steps.

Top comments (49)

Collapse
 
nowellmorrisla profile image
Nowell Morris

Also, a simple tr helps and removes "

curl http://localhost:9222/json/list | jq .[].url | tr -d '"' > mobile.tabs.txt

Collapse
 
aletedini profile image
Alete - ฿ 📈 • Edited

For those of you who have more than one instance of chrome running on your Android and ./adb forward tcp:9222 localabstract:chrome_devtools_remote shows you the wrong one, you may need to find the process of the other instance like this:
First I disabled the undesired chrome app (the one of my work profile, in my case), then,
adb shell "cat /proc/net/unix" (I wasn't able to grep that, because it's binary or something like that, I had to copy the output into a text editor and find "chrome_devtools_remote") in order to find the instance that was named: localabstract:chrome_devtools_remote_31723 in my case.
then:
./adb forward tcp:9222 localabstract:chrome_devtools_remote_31723 worked like a charm.

Thanks for this awesome trick!

Collapse
 
piczmar_0 profile image
Marcin Piczkowski

Awsome! Thanks for the tip, I will update the post with it.

Collapse
 
christophocles profile image
christophocles

THANK YOU!! I have wanted to clean this up for a long time, but as you are well aware, when one ends up in this situation, there are no easy options to clean it up. In my case, it got so bad that I could not even open the tab navigation anymore because it would cause Chrome to freeze and eventually crash. I could use the browser just fine (with some delay to initially open the browser), it was just difficult to switch tabs. I could only swipe left or right on the address bar to move to the adjacent tab, being careful not to swipe down because this would open the tab browser and crash. I had no idea how many tabs were open, and I also had no way to close tabs (!) because this can only be done from within the tab browser (or the Chrome Remote API, as I just learned today). As it turns out, I had about 7700 tabs open! Now the URLs are safely stored in an Excel sheet where I can sort/organize/bookmark/etc.

I am actually kind of amazed how well Chrome for Android was able to cope with this situation even as it got so ridiculously out of control. I was afraid one day the tab set would get completely corrupted and everything would be wiped out. This never happened.

In contrast, my secondary (work) phone is an iPhone 7 and it was in a similar situation but far less severe (maybe 200 tabs open). When Chrome crashed there, upon re-opening Chrome after the crash, it displayed a message for about 3 seconds that said "Chrome had a problem. Restore tabs?". If you did not click that restore button within those 3 seconds, the tabs were unrecoverably lost. I'm sure that even if I wanted to, I would not have been able to do a trick like this on the iPhone to back up my tabs. It was a completely hopeless situation, and that experience reinforces my preference to never voluntarily use an Apple product.

Next on the todo list is to adjust my habits so I don't end up in this situation again. This was an incredibly helpful first step on the road to recovery :)

Collapse
 
zapdash profile image
ZapDash

Yeah, once my accidentally vertical swipes turned into minutes of relaunching Chrome I started using Incognito tabs and bookmarking religiously. But I thought 732 tabs was a lot, and here you and the topic creator are pushing the multiple THOUSANDS! Color me impressed. And grateful to have found this guide!

Funnily enough, the much despised grid view Chrome pushed out actually helped me close more tabs in the past few months, since I could group them and then have subtabs with an accessible X button. And viewing the clustered groups actually worked better and didn't crash the app (as often).

But I concur, better browsing habits are a must for us digital hoarders.

Collapse
 
pierre profile image
Pierre-Henry Soria ✨

Thanks for this great step-by-step tutorial Marcin! I had sometimes about 70~90 tabs opened and, yes indeed, this can definitely be useful for cleaning them up (if you are sure you will read those URLs later). I now try to save interesting URLs to Pocket and read them offline when I have time, but still your trick can be helpful when we are in this kind of situation (especially with ~2500 opened tabs!).

Collapse
 
piczmar_0 profile image
Marcin Piczkowski

Glad that I could help. I'm curious why Chrome developers excluded the "Bookmark All Tabs" feature from mobile version, it would be useful so much.

Collapse
 
dkodr profile image
Dariusz Kuśnierek • Edited

Thanks a lot! This really helped me :-) I just made a small modification:

To parse the JSON and save it to a Markdown file (with titles and urls):

curl http://localhost:9222/json/list | jq -r ".[] | \"[\" + .title + \"](\" + .url + \")\"" > mobile.tabs.md
Enter fullscreen mode Exit fullscreen mode
Collapse
 
kangarooo profile image
kangarooo • Edited

How to make it URL clickable with a href and title to html file so i can import or click them?
what is wrong here?
curl localhost:9222/json/list | jq -r ".[] | \"(<a href="" + .url + \")">[\" + .title + \"]\"" > mobile.tabs.html

Collapse
 
benhadad profile image
benhadad

As a dev I understand the go-to method of writing code to solve a problem. The only issue here is that Chrome has a built-in way to do the same thing. This way does have 1 drawback, and that is it will open all the tabs on your computer first before you can bookmark them.

  1. Open a new chrome window (ctrl-N if you are in chrome)
  2. Go to history (ctrl-h)
  3. Select Tabs from other devices
  4. Find your other device
  5. Click on the action button (three vertical dots) and select open tabs
  6. Allow tabs to start to open, then select bookmark all open tabs (ctrl-Shift-D).

No code option.

Collapse
 
christophocles profile image
christophocles

This only works with recently-accessed tabs. It will not actually get ALL of the tabs that are currently open on the device, only maybe the last 50. So this "no code" option is not adequate. There is NO built-in way to do this properly; dev tools are the only way, and this is still true 1.5 years after you wrote this comment.

Collapse
 
piczmar_0 profile image
Marcin Piczkowski

Thanks. This is a good option too as long as you have your mobile Chrome tabs synchronized with Google account. Also, not sure how Chrome desktop browser would handle over 2000 open tabs.

Collapse
 
kangarooo profile image
kangarooo

Theres only 5 tabs. I have million open. You didnt help.

Collapse
 
sdkb profile image
sdkb

I'm glad there's some way to do this, but it's insane that it has to be this hard. It's a common issue — why can't the Chrome developers add an option for it?

Collapse
 
piczmar_0 profile image
Marcin Piczkowski

I'd like to know it as well.

Collapse
 
zapdash profile image
ZapDash

As someone who has never been adventurous enough to use Linux I still lament the shift away from user control and customizable options that the smartphone revolution has brought us. I swear there are about a dozen features in each major app that exist as total headscratchers or have been ignored (or worse, removed) over the years.

Collapse
 
imikari profile image
Will Wang

Marcin, THANK YOU!! This is so handy and solve my issue :)
Besides, I found that I have to add quotation marks for jq to make it work, FYI !

curl http://localhost:9222/json/list | jq '.[].url'
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jewelwildmoon profile image
Jewel Wildmoon

Would this work on a phone that wouldn't turn on? I'm currently getting an error "Your phone couldn't start normally. Some configuration data may be corrupt" so I'm trying to access all the tabs and groups I had open on Chrome. I believe I already had Developer's Mode on before this happened but I don't know if it was turned off when the phone updated to Android 11.
Phone is a Samsung A20 in case that's relevant.

Collapse
 
piczmar_0 profile image
Marcin Piczkowski

I have no idea, but maybe if you manage to boot in safe mode.

Collapse
 
jewelwildmoon profile image
Jewel Wildmoon

Yeah I got it to boot into Safe Mode today through the "Erase App Data" option for the error, but it ended up losing all the tabs.

Collapse
 
ranchercz profile image
ranchercz

It's best! but I have two spaces in my xiaomi phone and if I debugging first space all were done, but if I'm in second space, desktop chrome writes me error - webpage is not available and something like server is busy...in this second space I like to debugging because I have approximately 20000 tabs opened.. and what I have to do? Maybe I haven't enought buffer? Help!!

Collapse
 
piczmar_0 profile image
Marcin Piczkowski

Have you tried the trick with disabling one application (one space)? I've just added some more screens to the description.

Collapse
 
ranchercz profile image
ranchercz

Thanks so much

Some comments may only be visible to logged-in visitors. Sign in to view all comments.