-
-
Save maietta/051dc97dd256163414abc4c32bcbae9f 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 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