Forked from jsts/gist:e398fdaef7848f994f8d532b7df741b5
Last active
July 4, 2017 11:33
-
-
Save htggit/cc4da9532f8da2f76645bb247b844982 to your computer and use it in GitHub Desktop.
Revisions
-
gitlabc revised this gist
Jul 4, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ module.exports = { ``` ```bash alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" alias canary="/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary" alias chromium="/Applications/Chromium.app/Contents/MacOS/Chromium" chrome --headless --disable-gpu --dump-dom https://www.chromestatus.com/ -
gitlabc renamed this gist
Jul 4, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Headless Chrome Reference URL [https://developers.google.com/web/updates/2017/06/headless-karma-mocha-chai] ```js -
htggit revised this gist
Jun 21, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ Reference URL [https://developers.google.com/web/updates/2017/06/headless-karma-mocha-chai] ```js module.exports = { 'launcher:Chrome': ['type', ChromeBrowser], -
htggit revised this gist
Jun 21, 2017 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,13 @@ ```js module.exports = { 'launcher:Chrome': ['type', ChromeBrowser], 'launcher:ChromeHeadless': ['type', ChromeHeadlessBrowser], 'launcher:ChromeCanary': ['type', ChromeCanaryBrowser], 'launcher:ChromeCanaryHeadless': ['type', ChromeCanaryHeadlessBrowser], 'launcher:Chromium': ['type', ChromiumBrowser], 'launcher:Dartium': ['type', DartiumBrowser] } ``` ```bash alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" alias chrome-canary="/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary" -
htggit revised this gist
Jun 21, 2017 . 1 changed file with 79 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,4 +54,83 @@ async function launchChrome(headless = true) { launchChrome(true).then(chrome => { ... }); ``` ```bash yarn add chrome-remote-interface ``` ```js const CDP = require('chrome-remote-interface'); ... launchChrome().then(async chrome => { const version = await CDP.Version({port: chrome.port}); console.log(version['User-Agent'])); }); ``` ```js const CDP = require('chrome-remote-interface'); ... (async function() { const chrome = await launchChrome(); const protocol = await CDP({port: chrome.port}); // Extract the DevTools protocol domains we need and enable them. // See API docs: https://chromedevtools.github.io/devtools-protocol/ const {Page} = protocol; await Page.enable(); Page.navigate({url: 'https://www.chromestatus.com/'}); // Wait for window.onload before doing stuff. Page.loadEventFired(async () => { const manifest = await Page.getAppManifest(); if (manifest.url) { console.log('Manifest: ' + manifest.url); console.log(manifest.data); } else { console.log('Site has no app manifest'); } protocol.close(); chrome.kill(); // Kill Chrome. }); })(); ``` ```js const CDP = require('chrome-remote-interface'); ... (async function() { const chrome = await launchChrome(); const protocol = await CDP({port: chrome.port}); // Extract the DevTools protocol domains we need and enable them. // See API docs: https://chromedevtools.github.io/devtools-protocol/ const {Page, Runtime} = protocol; await Promise.all([Page.enable(), Runtime.enable()]); Page.navigate({url: 'https://www.chromestatus.com/'}); // Wait for window.onload before doing stuff. Page.loadEventFired(async () => { const js = "document.querySelector('title').textContent"; // Evaluate the JS expression in the page. const result = await Runtime.evaluate({expression: js}); console.log('Title of page: ' + result.result.value); protocol.close(); chrome.kill(); // Kill Chrome. }); })(); ``` -
htggit revised this gist
Jun 21, 2017 . 1 changed file with 9 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ ```bash alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" alias chrome-canary="/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary" alias chromium="/Applications/Chromium.app/Contents/MacOS/Chromium" @@ -12,9 +12,10 @@ chrome --headless --disable-gpu --screenshot https://www.chromestatus.com/ chrome --headless --disable-gpu --screenshot --window-size=1280,1696 https://www.chromestatus.com/ # Nexus 5x chrome --headless --disable-gpu --screenshot --window-size=412,732 https://www.chromestatus.com/ chrome --headless --disable-gpu --repl https://www.chromestatus.com/ ``` ```js const execFile = require('child_process').execFile; function launchHeadlessChrome(url, callback) { @@ -26,9 +27,11 @@ function launchHeadlessChrome(url, callback) { launchHeadlessChrome('https://www.chromestatus.com', (err, stdout, stderr) => { ... }); ``` ```bash yarn add lighthouse ``` ```js const chromeLauncher = require('lighthouse/chrome-launcher/chrome-launcher'); /** @@ -51,4 +54,4 @@ async function launchChrome(headless = true) { launchChrome(true).then(chrome => { ... }); ``` -
htggit revised this gist
Jun 21, 2017 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ ''' alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" alias chrome-canary="/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary" alias chromium="/Applications/Chromium.app/Contents/MacOS/Chromium" @@ -15,7 +15,6 @@ chrome --headless --disable-gpu --screenshot --window-size=412,732 https://www.c $ chrome --headless --disable-gpu --repl https://www.chromestatus.com/ const execFile = require('child_process').execFile; function launchHeadlessChrome(url, callback) { @@ -27,10 +26,9 @@ function launchHeadlessChrome(url, callback) { launchHeadlessChrome('https://www.chromestatus.com', (err, stdout, stderr) => { ... }); yarn add lighthouse const chromeLauncher = require('lighthouse/chrome-launcher/chrome-launcher'); /** -
htggit renamed this gist
Jun 21, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
htggit created this gist
Jun 21, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" alias chrome-canary="/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary" alias chromium="/Applications/Chromium.app/Contents/MacOS/Chromium" chrome --headless --disable-gpu --dump-dom https://www.chromestatus.com/ chrome --headless --disable-gpu --print-to-pdf https://www.chromestatus.com/ chrome --headless --disable-gpu --screenshot https://www.chromestatus.com/ # Size of a standard letterhead. chrome --headless --disable-gpu --screenshot --window-size=1280,1696 https://www.chromestatus.com/ # Nexus 5x chrome --headless --disable-gpu --screenshot --window-size=412,732 https://www.chromestatus.com/ $ chrome --headless --disable-gpu --repl https://www.chromestatus.com/ ''' const execFile = require('child_process').execFile; function launchHeadlessChrome(url, callback) { // Assuming MacOSx. const CHROME = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'; execFile(CHROME, ['--headless', '--disable-gpu', '--remote-debugging-port=9222', url], callback); } launchHeadlessChrome('https://www.chromestatus.com', (err, stdout, stderr) => { ... }); ''' yarn add lighthouse ''' const chromeLauncher = require('lighthouse/chrome-launcher/chrome-launcher'); /** * Launches a debugging instance of Chrome. * @param {boolean=} headless True (default) launches Chrome in headless mode. * False launches a full version of Chrome. * @return {Promise<ChromeLauncher>} */ async function launchChrome(headless = true) { return await chromeLauncher.launch({ // port: 9222, // Uncomment to force a specific port of your choice. chromeFlags: [ '--window-size=412,732', '--disable-gpu', headless ? '--headless' : '' ] }); } launchChrome(true).then(chrome => { ... }); '''