commit | e93e1b55453bae0bc433e50c7746b158babb3fc2 | [log] [tgz] |
---|---|---|
author | Yiming Zhou <uwyiming@google.com> | Sat Apr 06 02:04:34 2019 |
committer | Commit Bot <commit-bot@chromium.org> | Thu Apr 11 21:08:45 2019 |
tree | c2696d16dcda640a0d899f9134a65c6226a4502b | |
parent | 4d588b0f8d264c0cca087ec9dde7c6cc3d87e4c3 [diff] |
Let WPR inject scripts on pages with a CSP default-src directive. Web Page Replay has a feature that injects inline scripts into every page. Directives in the page's Content Security Policy (CSP) header can block inline scripts from executing. Most sites (99% in my experience) uses 'script-src' to specify CSP, but on rare occasions a site may use 'default-src' to specify CSP. A previous change opens injected script for execution when a page has a 'script-src' CSP. This change opens injected script for execution when a page has a 'default-src' CSP. This fix unblocks autofill test on dollarshaveclub.com. Bug: chromium:951847 Change-Id: I0ea2ed9fa3590a7658057cccc7e37a28c107839d Reviewed-on: https://chromium-review.googlesource.com/c/catapult/+/1556493 Reviewed-by: Caleb Rouleau <crouleau@chromium.org> Commit-Queue: Yiming Zhou <uwyiming@google.com>
Web Page Replay (WprGo) is a performance testing tool written in Golang for recording and replaying web pages. WprGo is currently used in Telemetry for Chrome benchmarking purposes. This requires go 1.8 and above. This has not been tested with earlier versions of go. It is supported on Windows, MacOS and Linux.
There are two ways to setup your GOPATH. The first is to use the go get
command to fetch this directory. This will use your default GOPATH, which is typically $HOME/go
:
go get github.com/catapult-project/catapult/web_page_replay_go
You can then find this directory in:
$HOME/go/src/github.com/catapult-project/catapult/web_page_replay_go
The second approach is to use your current catapult checkout. Assuming your “catapult” directory is located at $CATAPULT
, and assuming $HOME/go
is in your GOPATH, create the following symbolic link:
mkdir -p $HOME/go/src/github.com/catapult-project ln -s $CATAPULT $HOME/go/src/github.com/catapult-project/catapult
If you take this second approach, you will need to manually fetch the required packages:
go get github.com/urfave/cli go get golang.org/x/net/http2
Terminal 1:
Start wpr in record mode.
go run src/wpr.go record --http_port=8080 --https_port=8081 /tmp/archive.wprgo
...
Ctrl-C
Terminal 2:
google-chrome-beta --user-data-dir=$foo \ --host-resolver-rules="MAP *:80 127.0.0.1:8080,MAP *:443 127.0.0.1:8081,EXCLUDE localhost" --ignore-certificate-errors-spki-list=PhrPvGIaAMmd29hj8BCZOq096yj7uMpRNHpn5PDxI6I=
... wait for record servers to start
Terminal 1:
Start wpr in replay mode.
cd path/to/web_page_replay_go go run src/wpr.go replay --http_port=8080 --https_port=8081 /tmp/archive.wprgo
Terminal 2:
google-chrome-beta --user-data-dir=$bar \ --host-resolver-rules="MAP *:80 127.0.0.1:8080,MAP *:443 127.0.0.1:8081,EXCLUDE localhost" --ignore-certificate-errors-spki-list=PhrPvGIaAMmd29hj8BCZOq096yj7uMpRNHpn5PDxI6I=
... wait for replay servers to start
load the page
You will need a Linux host machine and an android device.
adb reverse tcp:8080 tcp:8080 adb reverse tcp:8081 tcp:8081
build/android/adb_chrome_public_command_line --host-resolver-rules="MAP *:80 127.0.0.1:8080,MAP *:443 127.0.0.1:8081,EXCLUDE localhost" \ --ignore-certificate-errors-spki-list=PhrPvGIaAMmd29hj8BCZOq096yj7uMpRNHpn5PDxI6I=
WebPageReplay uses self signed certificates for Https requests. To make Chrome trust these certificates, you can use --ignore-certificate-errors-spki-list like above. If that doesn't work, you may try installing a test certificate authority as a local trust anchor. Note: Please do this with care because installing the test root CA compromises your machine. This is currently only supported on Linux and Android.
Installing the test CA. Specify a --android_device_id
if you'd like to install the root CA on an android device.
go run src/wpr.go installroot
Uninstall the test CA. Specify a --android_device_id
if you'd like to remove the root CA from an android device.
go run src/wpr.go removeroot
go run src/wpr.go replay --https_port=8081 --https_to_http_port=8082 \ /tmp/archive.wprgo
google-chrome-beta --user-data-dir=$foo \ --host-resolver-rules="MAP *:443 127.0.0.1:8081,EXCLUDE localhost" \ --ignore-certificate-errors-spki-list=PhrPvGIaAMmd29hj8BCZOq096yj7uMpRNHpn5PDxI6I= \ --proxy-server=http=https://127.0.0.1:8082 \ --trusted-spdy-proxy=127.0.0.1:8082
httparchive.go is a convenient script to inspect a wprgo archive. Use ls
,cat
and edit
. Options are available to specify request url host (--host
) and path (--full-path
).
E.g.
go run src/httparchive.go ls /tmp/archive.wprgo --host=example.com --full-path=/index.html
Run all tests in a specific file.
go test transformer_test.go transformer.go
Run all tests in webpagereplay
module.
go test webpagereplay -run ''
wpr_public_hash.txt is generated from wpr_cert.pem using the command below.
openssl x509 -noout -pubkey -in wpr_cert.pem | \ openssl pkey -pubin -outform der | \ openssl dgst -sha256 -binary | \ base64
Please read contributor's guide. We use the Catapult issue tracker for bugs and features. Once your change is reviewed and ready for landing, please run telemetry/bin/update_wpr_go_binary
to update binaries in Google cloud storage.
Please email telemetry@chromium.org.