Skip to content

Commit

Permalink
Merge pull request #27 from holsee/feature/protocol-flags
Browse files Browse the repository at this point in the history
Support selection of Chrome DevTools protocol version (and fixes current version which is incomplete)
  • Loading branch information
andrewvy authored May 2, 2019
2 parents e2612bb + a04cde3 commit 3a17b9c
Show file tree
Hide file tree
Showing 6 changed files with 29,460 additions and 5,271 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ def deps do
end
```

### Chrome DevTools Protocol Selection

Chrome Remote Interface generated its API at compile time from the protocol
definition released by the Chrome DevTools Team.
For more info see: [https://chromedevtools.github.io/devtools-protocol/](https://chromedevtools.github.io/devtools-protocol/)

This can be overridden by setting `CRI_PROTOCOL_VERSION` environment variable
to:
* 1-2
* 1-3 * default
* tot

Example:
```
CRI_PROTOCOL_VERSION=1-2 mix compile
CRI_PROTOCOL_VERSION=1-3 mix compile
CRI_PROTOCOL_VERSION=tot mix compile
```

## Usage

> Note: In these examples, it assumes you're already running chrome headless with remote debugging enabled.
Expand Down
27 changes: 20 additions & 7 deletions lib/chrome_remote_interface.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,29 @@ defmodule ChromeRemoteInterface do

alias ChromeRemoteInterface.PageSession

@protocol_env_key "CRI_PROTOCOL_VERSION"
@protocol_versions ["1-2", "1-3", "tot"]
@protocol_version (
if (vsn = System.get_env(@protocol_env_key)) in @protocol_versions do
vsn
else
"1-3"
end
)
IO.puts("Compiling ChromeRemoteInterface with Chrome DevTools Protocol version: '#{@protocol_version}'")

@doc """
Gets the current version of the Chrome Debugger Protocol
"""
def protocol_version() do
@protocol_version
end

protocol =
File.read!("priv/protocol.json")
File.read!("priv/#{@protocol_version}/protocol.json")
|> Poison.decode!()


# Generate ChromeRemoteInterface.RPC Modules

Enum.each(protocol["domains"], fn(domain) ->
Expand Down Expand Up @@ -58,10 +77,4 @@ defmodule ChromeRemoteInterface do
end
end
end)

@protocol_version "#{protocol["version"]["major"]}.#{protocol["version"]["minor"]}"
@doc """
Gets the current version of the Chrome Debugger Protocol
"""
def protocol_version(), do: @protocol_version
end
Loading

0 comments on commit 3a17b9c

Please sign in to comment.