When you never close tabs on your mobile Chrome browser
Tags: tips, mobile
Published: 2019-03-07 14:30:55

---
title: When you never close tabs on your mobile Chrome browser
published: true
description: Useful tip how to dump all open tabs on mobile Chrome browser to a text file.
tags: tips, mobile
---

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](https://developer.android.com/studio), but you could also try the stand-alone sdk tool available from [here](https://developer.android.com/studio) 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.

2. 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](https://developer.android.com/studio/debug/dev-options) 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](https://developer.android.com/studio/debug/dev-options#networking), 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
```
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
```

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](https://developer.chrome.com/devtools/docs/remote-debugging-legacy).
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
```
[Here](https://www.girish.in/how-remote-debugging-works-in-chrome/) 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](http://localhost:9222)

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

It looks like that: 

![JSON](https://thepracticaldev.s3.amazonaws.com/i/v4frqhw4fdrw7cphde4m.png)

If you have [JQ](https://stedolan.github.io/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
```

UPDATE:
(Thanks to [Alete](https://dev.to/aletedini) 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](https://thepracticaldev.s3.amazonaws.com/i/l6j8fg8l5qdwi9xjn84z.jpg)

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

![Show popup menu](https://thepracticaldev.s3.amazonaws.com/i/3g16h728xwxbdjwwqzw6.jpg)

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

![App info](https://thepracticaldev.s3.amazonaws.com/i/epsx63h9jcy3tnpj06ci.jpg)

Next, click "Disable" button.

Then on your PC in command line execute:

```bash
adb shell "cat /proc/net/unix" 
```
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 

```bash
./adb forward tcp:9222 localabstract:chrome_devtools_remote_31723
```

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