b5032069e3
- Refactored chromedp-gen and cdp code so that Execute no longer returns a channel - Fixing potential race problems in handler - Eliminated some dead code - Updated examples to include new logging parameters |
||
---|---|---|
.. | ||
fixup | ||
gen | ||
internal | ||
templates | ||
build.sh | ||
main.go | ||
protocol.json | ||
README.md | ||
update.sh |
About chromedp-gen
chromedp-gen
is a standalone cli tool for the chromedp
package that generates the types for the chrome domain APIs as defined in
Chrome's protocol.json
.
Updating protocol.json
Run update.sh
to retrieve and combine the latest
browser_protocol.json
and
js_protocol.json
from the Chromium source tree into protocol.json
.
Installing quicktemplate and easyjson
chromedp-gen
uses quicktemplate for
code generation templates, and uses easyjson
for JSON marshaling/unmarshaling.
Unfortunately, both of these projects cannot be used directly out of the box,
as the versions used by chromedp-gen
make use of a couple minor modifications:
- quicktemplate has been modified to recognize '{% end %}' templates
- easyjson has been modified to always output generated code in the same order (previously, the mailru version did not always generate the same output, as a couple points in the code were being affected by the Go map/key order issue).
I (kenshaw) have put in issues/pull requests to both projects in the hope that the changes I've made get merged and/or fixed otherwise.
For now, the exact versions that are in use with chromedp-gen
can be obtained
on my personal Github account:
The commands (and their associated dependencies) can be installed in the usual Go way:
go get -u github.com/kenshaw/quicktemplate/qtc github.com/kenshaw/easyjson/easyjson
Each package provides a command (qtc
and easyjson
, respectively) that need
to be available on the path for the chromedp-gen
command to work.
Generating types for chromedp
Assuming the qtc
and easyjson
commands are available (see above), one can
then run the build.sh
which will handle generating template
files, and building/invoking the chromedp-gen
command.
Reference Output
The output of running update.sh
and build.sh
is below:
ken@ken-desktop:~/src/go/src/github.com/knq/chromedp/cmd/chromedp-gen$ ./update.sh
# download
curl -s $BROWSER_PROTO | base64 -d > $BROWSER_TMP
curl -s $JS_PROTO | base64 -d > $JS_TMP
# merge browser_protocol.json and js_protocol.json
jq -s '[.[] | to_entries] | flatten | reduce .[] as $dot ({}; .[$dot.key] += $dot.value)' $BROWSER_TMP $JS_TMP > $OUT
# convert boolean values listed as strings to real booleans
# (this is not used in favor of using the custom Bool type that correctly JSON unmarshals the value)
# left here for completeness
#perl -pi -e 's/"\s*:\s*"(true|false)"/": \1/g' $OUT
ken@ken-desktop:~/src/go/src/github.com/knq/chromedp/cmd/chromedp-gen$ ./build.sh
go generate
qtc: 2017/01/29 09:10:16 Compiling *.qtpl template files in directory "templates"
qtc: 2017/01/29 09:10:16 Compiling "templates/domain.qtpl" to "templates/domain.qtpl.go"...
qtc: 2017/01/29 09:10:16 Compiling "templates/extra.qtpl" to "templates/extra.qtpl.go"...
qtc: 2017/01/29 09:10:16 Compiling "templates/file.qtpl" to "templates/file.qtpl.go"...
qtc: 2017/01/29 09:10:16 Compiling "templates/type.qtpl" to "templates/type.qtpl.go"...
qtc: 2017/01/29 09:10:16 Total files compiled: 4
go build
time ./chromedp-gen
2017/01/29 09:10:17 skipping command Page.getCookies [redirect:Network]
2017/01/29 09:10:17 skipping command Page.deleteCookie [redirect:Network]
2017/01/29 09:10:17 skipping command Page.setDeviceMetricsOverride [redirect:Emulation]
2017/01/29 09:10:17 skipping command Page.clearDeviceMetricsOverride [redirect:Emulation]
2017/01/29 09:10:17 skipping command Page.setGeolocationOverride [redirect:Emulation]
2017/01/29 09:10:17 skipping command Page.clearGeolocationOverride [redirect:Emulation]
2017/01/29 09:10:17 skipping command Page.setDeviceOrientationOverride [redirect:DeviceOrientation]
2017/01/29 09:10:17 skipping command Page.clearDeviceOrientationOverride [redirect:DeviceOrientation]
2017/01/29 09:10:17 skipping command Page.setTouchEmulationEnabled [redirect:Emulation]
2017/01/29 09:10:17 skipping command param Emulation.setDeviceMetricsOverride.offsetX [deprecated]
2017/01/29 09:10:17 skipping command param Emulation.setDeviceMetricsOverride.offsetY [deprecated]
2017/01/29 09:10:17 skipping command param Tracing.start.categories [deprecated]
2017/01/29 09:10:17 skipping command param Tracing.start.options [deprecated]
2017/01/29 09:10:17 skipping domain Console (console) [deprecated]
2017/01/29 09:10:17 running goimports
2017/01/29 09:10:31 running easyjson (stubs)
2017/01/29 09:10:31 running easyjson
2017/01/29 09:10:39 done.
real 0m22.318s
user 1m15.132s
sys 0m53.592s
go install ../../cdp/...
ken@ken-desktop:~/src/go/src/github.com/knq/chromedp/cmd/chromedp-gen$