I'd like to write a shell script that automatically transfers all tabs from Chrome to Firefox (by getting the list of tabs from Chrome, and then opening them in Firefox with a script.) In Google Chrome, is it possible to obtain a list of open tabs via the command line?


5 Answers 5


This question was not answered, solution above is for Chrome Dev Tools where the OP asked in CLI, so this is the solution I've found :

strings ~/.config/google-chrome/Default/Current\ Session | grep -E '^https?://'
  • 6
    This answer seems not work after Chrome v87. There is no Current\ Session anymore.
    – roachsinai
    Nov 20, 2020 at 4:08
  • 1
    The file is now ~/.config/google-chrome/Default/Sessions/Tabs* but there may be more than one file so I assume you'll have to use the file with the greatest number to get the current session tabs.
    – mchid
    Sep 14, 2022 at 21:12
  • 1
    I have submitted an edit for strings "$(find ~/.config/google-chrome/Default/Sessions/Tabs* | tail -1)" | grep -E '^https?://' which will select the most recently created Tabs file (the current session).
    – mchid
    Sep 14, 2022 at 21:25

For a macOS only solution, you could also use the open-source utility chrome-cli. You can install with Homebrew:

brew install chrome-cli

Also, take note of one thing from the README:

To execute javascript you must first allow it under View > Developer > Allow JavaScript from Apple Events.

Here's what it looks like:

$ chrome-cli list tabs
[1889] Edit - Super User
[1918] prasmussen/chrome-cli: Control Google Chrome from the command line
[1905] Yotto Winter Mix 19 by Yotto
$ chrome-cli list links
[1889] https://superuser.com/posts/1407956/edit
[1918] https://github.com/prasmussen/chrome-cli
[1905] https://soundcloud.com/yotto/yotto-winter-mix-2019

I finally found a duplicate question (it took a lot of searching to find it, though): https://stackoverflow.com/questions/4968271/chrome-on-linux-query-the-browser-to-see-what-tabs-are-open


I wish I knew about chrome-cli...

This is also a OSX only solution, i use applescript:

function chrome_json_summary() {
local wincount=$(osascript -e 'tell application "Google Chrome" to get number of windows')
[ "$wincount" -eq 0 ] && echo "zero windows!" && return

local json="["
for (( i=1; i<=$wincount; i++)); do
    local cmd="osascript -e 'tell application \"Google Chrome\" to get number of tabs in window $i'"
    local tabcount=$(eval $cmd)
    for (( j=1; j<=$tabcount; j++)); do
        local cmd="osascript -e 'tell application \"Google Chrome\" to get URL of tab $j of window $i'"
        local url=$(eval $cmd)
        [ $j -eq $tabcount ] && json="$json\"$url\"" || json="$json\"$url\","
   [ $i -eq $wincount ] && json="$json]" || json="$json],"
echo "$json]"

This bash function uses applescript to iterate over all chrome windows and each tab in each window to build a array of arrays json.

I store the json in a local file. i use this to backup my chrome state. this script would be faster if i did the json generation all in applescript.

I have a separate function that loads a json file into chrome.

the advantage of this over chrome-cli would be that applescript (plus basic bash scripting) will pretty much not break with osx upgrades.


I have written a tool to extract data from chrome session files for precisely this purpose. https://github.com/lemnos/chrome-session-dump. Running it like so chrome-session-dump will produce a list of tabs (in order) which can subsequently be passed to firefox. E.G chrome-session-dump|xargs firefox. You can also obtain the currently open tab via -active for processing by external scripts.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .