Created
April 2, 2019 22:05
-
-
Save guillemcanal/01465404aacba11452602937bb89ef6d to your computer and use it in GitHub Desktop.
control a chrome instance running on you Mac using a containerized puppeteer script
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 characters
// First, run a Chrome instance on your Mac: | |
// /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 &> /dev/null &; disown | |
const puppeteer = require('puppeteer-core'); | |
const axios = require('axios'); | |
const getBrowserWSEndpoint = async (baseUrl) => { | |
const response = await axios.get(`http://${baseUrl}/json/version`); | |
return response.data.webSocketDebuggerUrl; | |
}; | |
const getPuppeteerBrowser = async () => { | |
const baseUrl = 'docker.for.mac.localhost:9222'; | |
const options = { | |
defaultViewport: null, | |
browserWSEndpoint: await getBrowserWSEndpoint(baseUrl) | |
}; | |
return puppeteer.connect(options); | |
}; | |
(async () => { | |
const browser = await getPuppeteerBrowser(); | |
const page = await browser.newPage(); | |
await page.goto('https://google.com'); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment