Skip to content

Commit 3a17b9c

Browse files
authored
Merge pull request #27 from holsee/feature/protocol-flags
Support selection of Chrome DevTools protocol version (and fixes current version which is incomplete)
2 parents e2612bb + a04cde3 commit 3a17b9c

File tree

6 files changed

+29460
-5271
lines changed

6 files changed

+29460
-5271
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ def deps do
1919
end
2020
```
2121

22+
### Chrome DevTools Protocol Selection
23+
24+
Chrome Remote Interface generated its API at compile time from the protocol
25+
definition released by the Chrome DevTools Team.
26+
For more info see: [https://chromedevtools.github.io/devtools-protocol/](https://chromedevtools.github.io/devtools-protocol/)
27+
28+
This can be overridden by setting `CRI_PROTOCOL_VERSION` environment variable
29+
to:
30+
* 1-2
31+
* 1-3 * default
32+
* tot
33+
34+
Example:
35+
```
36+
CRI_PROTOCOL_VERSION=1-2 mix compile
37+
CRI_PROTOCOL_VERSION=1-3 mix compile
38+
CRI_PROTOCOL_VERSION=tot mix compile
39+
```
40+
2241
## Usage
2342

2443
> Note: In these examples, it assumes you're already running chrome headless with remote debugging enabled.

lib/chrome_remote_interface.ex

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,29 @@ defmodule ChromeRemoteInterface do
55

66
alias ChromeRemoteInterface.PageSession
77

8+
@protocol_env_key "CRI_PROTOCOL_VERSION"
9+
@protocol_versions ["1-2", "1-3", "tot"]
10+
@protocol_version (
11+
if (vsn = System.get_env(@protocol_env_key)) in @protocol_versions do
12+
vsn
13+
else
14+
"1-3"
15+
end
16+
)
17+
IO.puts("Compiling ChromeRemoteInterface with Chrome DevTools Protocol version: '#{@protocol_version}'")
18+
19+
@doc """
20+
Gets the current version of the Chrome Debugger Protocol
21+
"""
22+
def protocol_version() do
23+
@protocol_version
24+
end
25+
826
protocol =
9-
File.read!("priv/protocol.json")
27+
File.read!("priv/#{@protocol_version}/protocol.json")
1028
|> Poison.decode!()
1129

30+
1231
# Generate ChromeRemoteInterface.RPC Modules
1332

1433
Enum.each(protocol["domains"], fn(domain) ->
@@ -58,10 +77,4 @@ defmodule ChromeRemoteInterface do
5877
end
5978
end
6079
end)
61-
62-
@protocol_version "#{protocol["version"]["major"]}.#{protocol["version"]["minor"]}"
63-
@doc """
64-
Gets the current version of the Chrome Debugger Protocol
65-
"""
66-
def protocol_version(), do: @protocol_version
6780
end

0 commit comments

Comments
 (0)