1 | # Chromix-Too
|
2 |
|
3 | This project provides external (e.g. command-line or scripted) access to Chrome's internal (Javascript) API's.
|
4 |
|
5 | For example, the following command closes all tabs on stackoverflow:
|
6 |
|
7 | chromix-too rm stackoverflow.com
|
8 |
|
9 | Chromix-too is a replacement for
|
10 | [chromix](https://github.com/smblott-github/chromix). Chromix-too is
|
11 | considerably simpler, uses a Unix-domain socket for communication between
|
12 | client and server (which is more secure), and is better packaged (it can be used as a module too).
|
13 |
|
14 | ## Getting started
|
15 |
|
16 | There are three components: a chrome extension, a server and the `chromix-too` utility.
|
17 |
|
18 | Install [the extension](https://chrome.google.com/webstore/detail/chromix-too/ppapdfccnamacakfkpfmpfnefpeajboj) from the Chrome Store.
|
19 |
|
20 | To install the server and the `chromix-too` utility:
|
21 |
|
22 | ```shell
|
23 | sudo npm install -g chromix-too
|
24 | ```
|
25 |
|
26 | Next, you need to run the server:
|
27 |
|
28 | ```shell
|
29 | chromix-too-server
|
30 | ```
|
31 |
|
32 | And try out the client:
|
33 |
|
34 | ```shell
|
35 | chromix-too ls
|
36 | ```
|
37 |
|
38 | Of course, you need to keep the server running all the time. There are many ways to do this, but I use [daemontools](https://cr.yp.to/daemontools.html); my daemontools `run` file is just:
|
39 |
|
40 | ```shell
|
41 | PATH="/usr/local/bin:$PATH"
|
42 | HOME='/home/blott' exec setuidgid blott chromix-too-server
|
43 | ```
|
44 |
|
45 | (Or perhaps just leave the server running in a tmux session.)
|
46 |
|
47 | ## Commands
|
48 |
|
49 | List tabs:
|
50 |
|
51 | ```shell
|
52 | chromix-too ls
|
53 | ```
|
54 |
|
55 | List just tab Ids:
|
56 |
|
57 | ```shell
|
58 | chromix-too tid
|
59 | ```
|
60 |
|
61 | Focus a tab:
|
62 |
|
63 | ```shell
|
64 | chromix-too focus https://github.com/smblott-github/chromix
|
65 | ```
|
66 |
|
67 | Select a tab (select the tab but don't `focus` Chrome window):
|
68 |
|
69 | ```shell
|
70 | chromix-too select https://github.com/smblott-github/chromix
|
71 | ```
|
72 |
|
73 | Remove a tab:
|
74 |
|
75 | ```shell
|
76 | chromix-too rm https://github.com/smblott-github/chromix
|
77 | ```
|
78 |
|
79 | Reload a tab:
|
80 |
|
81 | ```shell
|
82 | chromix-too reload https://github.com/smblott-github/chromix
|
83 | ```
|
84 |
|
85 | Open a tab:
|
86 |
|
87 | ```shell
|
88 | chromix-too open https://github.com/smblott-github/chromix
|
89 | ```
|
90 |
|
91 | View a file:
|
92 |
|
93 | ```shell
|
94 | chromix-too file ./README.html
|
95 | ```
|
96 |
|
97 | (The `file` command also focuses and reloads an existing tab if one exists.)
|
98 |
|
99 | Verify that everything is running correctly:
|
100 |
|
101 | ```shell
|
102 | chromix-too ping
|
103 | ```
|
104 |
|
105 | ### Raw JSON
|
106 |
|
107 | Call any available Chrome function from the command line:
|
108 |
|
109 | ```shell
|
110 | chromix-too raw chrome.storage.local.set '{"pi": 3.141}'
|
111 |
|
112 | chromix-too raw chrome.storage.local.get pi
|
113 | # {"pi":3.141}
|
114 |
|
115 | chromix-too raw chrome.storage.local.get pi | jq '.pi'
|
116 | # 3.141
|
117 | ```
|
118 |
|
119 | ## Filters
|
120 |
|
121 | For all of the commands above (except where it doesn't make sense), you can
|
122 | filter the list of tabs to which the command applies.
|
123 |
|
124 | There are three kinds of filter:
|
125 |
|
126 | 1. If the filter is just a bare number, then it is interpreted as a tab Id.
|
127 |
|
128 | 2. If the filter is one of the boolean options described
|
129 | [here](https://developer.chrome.com/extensions/tabs#method-query), then the
|
130 | corresponding flag is set. For example, you can use `pinned` to operate on all pinned tabs.
|
131 |
|
132 | These boolean flags can be inverted: `-pinned` selects all unpinned tabs.
|
133 |
|
134 | 3. Any remaining filter arguments are treated as queries. Tabs are removed
|
135 | from consideration unless the query text is present in either the tab's URL
|
136 | or the tab's title.
|
137 |
|
138 | Examples:
|
139 |
|
140 | ```shell
|
141 | # Remove the tab with this tab Id.
|
142 | chromix-too rm 1234
|
143 |
|
144 | # Remove all audible tabs.
|
145 | chromix-too rm audible
|
146 |
|
147 | # Remove all unpinned tabs.
|
148 | chromix-too rm -pinned
|
149 |
|
150 | # List GMail tabs.
|
151 | chromix-too ls mail.google.com
|
152 |
|
153 | # Focus my Google Inbox tab.
|
154 | chromix-too focus Inbox smblott@gmail.com
|
155 | ```
|
156 |
|
157 | All commands which accept filters fail (so, yield a non-zero exit status) if there are no matching tabs.
|
158 |
|
159 | ## Usage as a module
|
160 |
|
161 | It is also possible to use `chromix-too` as a node module; here's an example:
|
162 |
|
163 | ```Coffeescript
|
164 | chromix = require("chromix-too")().chromix
|
165 |
|
166 | chromix "chrome.storage.local.set", {}, {pi: 3.141}, ->
|
167 | chromix "chrome.storage.local.get", {}, "pi", (response) ->
|
168 | console.log response.pi
|
169 | ```
|
170 |
|
171 | The second argument (`{}`, here) is a place holder for future extensions.
|
172 |
|
173 | The general form is:
|
174 |
|
175 | ```Coffeescript
|
176 | chromix PATH, REQUEST, ARGS..., CALLBACK
|
177 | ```
|
178 |
|
179 | The number of `ARGS...` provided must match the number of (non-callback) arguments expected by the relevant
|
180 | Chrome API call. When the call is actually made, chromix-too simply
|
181 | appends its own callback, and that callback must be in the correct argument position.
|
182 |
|
183 | ## Known issues
|
184 |
|
185 | - There is currently no way to set the websocket port used between the Chrome extension and the server.
|
186 | - Only background-page API calls are possible. It is intended to add the ability to invoke functions in a content script at some point in the future.
|
187 |
|
188 | Contributions are welcome.
|