diff --git a/docs/headless-chrome.md b/docs/headless-chrome.md index f04f176e7fd2..9a2dea825853 100644 --- a/docs/headless-chrome.md +++ b/docs/headless-chrome.md @@ -55,6 +55,30 @@ xvfb-run --server-args='-screen 0, 1024x768x16' \ lighthouse --port=9222 https://github.com ``` +## Posting Lighthouse reports to GitHub Gists + +Be sure to replace `${GITHUB_OWNER}` and `${GITHUB_TOKEN}` with your own credentials. The code below is tested on Ubuntu. + +```sh +apt-get install -y nodejs npm chromium jq +npm install -g lighthouse + +# Run lighthouse as JSON, pipe it to jq to wrangle and send it to GitHub Gist via curl +# so Lighthouse Viewer can grab it. +lighthouse "http://localhost" --chrome-flags="--no-sandbox --headless" \ + --output json \ +| jq -r "{ description: \"YOUR TITLE HERE\", public: \"false\", files: {\"$(date "+%Y%m%d").lighthouse.report.json\": {content: (. | tostring) }}}" \ +| curl -sS -X POST -H 'Content-Type: application/json' \ + -u ${GITHUB_OWNER}:${GITHUB_TOKEN} \ + -d @- https://api.github.com/gists > results.gist + +# Let's be nice and add the Lighthouse Viewer link in the Gist description. +GID=$(cat results.gist | jq -r '.id') && \ +curl -sS -X POST -H 'Content-Type: application/json' \ + -u ${GITHUB_OWNER}:${GITHUB_TOKEN} \ + -d "{ \"description\": \"YOUR TITLE HERE - Lighthouse: https://googlechrome.github.io/lighthouse/viewer/?gist=${GID}\" }" "https://api.github.com/gists/${GID}" > updated.gist +``` + ## Node module Install: