• Stars
    star
    2,514
  • Rank 18,250 (Top 0.4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Control Google Chrome from the command line

chrome-cli

Overview

chrome-cli is a command line utility for controlling Google Chrome compatible browsers on OS X. It is a native binary that uses the Scripting Bridge to communicate with Chrome. chrome-cli has been tested with the following browsers:

  • Chrome
  • Chrome Canary
  • Chromium
  • Brave
  • Vivaldi
  • Edge

Other browsers

By default chrome-cli communicates with Chrome, but you can use it with other browsers by settings the CHROME_BUNDLE_IDENTIFIER environment variable. I.e. to use chrome-cli with Brave you can run the following command:

CHROME_BUNDLE_IDENTIFIER="com.brave.Browser" chrome-cli list tabs

Check the scripts directory for some convenient wrappers.

How do I find the bundle identifier?

The following command will print out the bundle identifier for Brave

mdls -name kMDItemCFBundleIdentifier -raw /Applications/Brave\ Browser.app

Installation

Homebrew

brew install chrome-cli

This will install:

  • chrome-cli
  • chrome-canary-cli
  • chromium-cli
  • brave-cli
  • vivaldi-cli
  • edge-cli

JavaScript execution and viewing source

To execute javascript or to view a tab's source you must first enable View > Developer > Allow JavaScript from Apple Events. More details here. Thanks to @kevinfrommelt and @paulp for providing this information.

Usage

chrome-cli -h  (Print help)
chrome-cli --help  (Print help)
chrome-cli help  (Print help)
chrome-cli list windows  (List all windows)
chrome-cli list tabs  (List all tabs)
chrome-cli list tabs -w <id>  (List tabs in specific window)
chrome-cli list links  (List all tabs' link)
chrome-cli list links -w <id>  (List tabs' link in specific window)
chrome-cli info  (Print info for active tab)
chrome-cli info -t <id>  (Print info for specific tab)
chrome-cli open <url>  (Open url in new tab)
chrome-cli open <url> -n  (Open url in new window)
chrome-cli open <url> -i  (Open url in new incognito window)
chrome-cli open <url> -t <id>  (Open url in specific tab)
chrome-cli open <url> -w <id>  (Open url in new tab in specific window)
chrome-cli close  (Close active tab)
chrome-cli close -w  (Close active window)
chrome-cli close -t <id>  (Close specific tab)
chrome-cli close -w <id>  (Close specific window)
chrome-cli reload  (Reload active tab)
chrome-cli reload -t <id>  (Reload specific tab)
chrome-cli back  (Navigate back in active tab)
chrome-cli back -t <id>  (Navigate back in specific tab)
chrome-cli forward  (Navigate forward in active tab)
chrome-cli forward -t <id>  (Navigate forward in specific tab)
chrome-cli activate -t <id>  (Activate specific tab)
chrome-cli presentation  (Enter presentation mode with the active tab)
chrome-cli presentation -t <id>  (Enter presentation mode with a specific tab)
chrome-cli presentation exit  (Exit presentation mode)
chrome-cli size  (Print size of active window)
chrome-cli size -w <id>  (Print size of specific window)
chrome-cli size <width> <height>  (Set size of active window)
chrome-cli size <width> <height> -w <id>  (Set size of specific window)
chrome-cli position  (Print position of active window)
chrome-cli position -w <id>  (Print position of specific window)
chrome-cli position <x> <y>  (Set position of active window)
chrome-cli position <x> <y> -w <id>  (Set position of specific window)
chrome-cli source  (Print source from active tab)
chrome-cli source -t <id>  (Print source from specific tab)
chrome-cli execute <javascript>  (Execute javascript in active tab)
chrome-cli execute <javascript> -t <id>  (Execute javascript in specific tab)
chrome-cli chrome version  (Print Chrome version)
chrome-cli version  (Print application version)

JSON output

You can set the environment variable OUTPUT_FORMAT to json to get json output. For example:

$ OUTPUT_FORMAT=json chrome-cli list tabs
{
  "tabs" : [
    {
      "id" : 1869578516,
      "title" : "Lobsters",
      "url" : "https://lobste.rs/",
      "windowId" : 1869578514,
      "windowName" : "Lobsters"
    }
  ]
}

Examples

List tabs
$ chrome-cli list tabs
[57] Inbox (1) - [email protected] - Gmail
[2147] My Drive - Google Drive
[2151] GitHub
[2161]
[2155] Hacker News
Print tab info
$ chrome-cli info -t 2161
Id: 2162
Title:
Url: http://httpbin.org/ip
Loading: No
Print tab source
$ chrome-cli source -t 2161
<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{
  "origin": "1.2.3.4"
}</pre></body></html>
Extract information from page
$ chrome-cli execute '(function() { var nodes = document.querySelectorAll(".title a"); var titles = []; for (var i = 0; i < 5; i++) { titles.push(nodes[i].innerHTML) } return titles.join("\n"); })();' -t 2155
High-Speed Trading Isn't About Efficiency—It's About Cheating
The terrifying surveillance case of Brandon Mayfield
Google turns on "Download Gmail Archive" feature
Learning to Code vs Learning Computer Science
Show HN: Crushify.org

More Repositories

1

gdrive

Google Drive CLI Client
Go
8,973
star
2

glot-run

API for running code inside docker containers
Erlang
148
star
3

glot-code-runner

Code runner
Go
115
star
4

glot-containers

Docker containers for running code
Dockerfile
87
star
5

glot-snippets

API for storing code snippets
Erlang
52
star
6

git-vanity-hash

CLI tool for creating commit hashes with a specific prefix
Rust
41
star
7

gandi-api

Go library for the gandi.net API
Go
23
star
8

orri

A web service for hosting websites
Rust
21
star
9

glot.io

DEPRECATED: Pastebin clone built with AngularJS and CouchDB
JavaScript
19
star
10

re

A command line utility for pattern matching similar to 'grep', but supports capture groups and multiline matches.
Go
16
star
11

glot-cli

Command line tool for interacting with the glot api
Go
10
star
12

gandi

Gandi.net CLI tools
Go
8
star
13

cert

Generate self-signed certificates
Go
5
star
14

spotify-track

CLI tool that prints the currently playing song in Spotify
Objective-C
5
star
15

SensorBox

Arduino sensor box
Arduino
4
star
16

glot-run2

Rust
4
star
17

smartimages

SmartOS IMGAPI Server
Go
4
star
18

gandi-rrr

gandi - Restful Resource Records
Go
2
star
19

notification

CLI tool for creating OS X Notification Center messages
Objective-C
2
star
20

magmod

A magento module generator
Haskell
2
star
21

Performance-Debugging

C
2
star
22

daemons

Start configured applications inside a tmux session
Go
2
star
23

reminders

https://reminders.rasmussen.io/
Elm
2
star
24

pwgen

Web site that generates pronounceable passwords.
JavaScript
2
star
25

Telegraph

C#
1
star
26

imgserver

Smartos dataset server
JavaScript
1
star
27

glot-api-lib

glot api libraries
Go
1
star
28

pushover-irssi

pushover.net irssi script with idle detection
Perl
1
star
29

itunes-track

CLI tool that prints the currently playing song in iTunes
Objective-C
1
star
30

wolfram

IRC bot
JavaScript
1
star
31

iTwatch

#twatch app for iPhone
1
star