How Can I Get Chrome's Remote Debug URL When Using The "remote-debugging-port" In Electron?
I've set the remote-debugging-port option for Chrome in my Electron main process: app.commandLine.appendSwitch('remote-debugging-port', '8315') Now, how can I get the ws:// URL th
Solution 1:
Here's how to connect Puppeteer to your Electron window from your Electron main process code:
app.commandLine.appendSwitch('remote-debugging-port', '8315')
async function test() {
const response = await fetch(`http://localhost:8315/json/list?t=${Math.random()}`)
const debugEndpoints = await response.json()
let webSocketDebuggerUrl = ''
for (const debugEndpoint of debugEndpoints) {
if (debugEndpoint.title === 'Saffron') {
webSocketDebuggerUrl = debugEndpoint.webSocketDebuggerUrl
break
}
}
const browser = await puppeteer.connect({
browserWSEndpoint: webSocketDebuggerUrl
})
// use puppeteer APIs now!
}
// ... make your window, etc, the usual, and then: ...
// wait for the window to open/load, then connect Puppeteer to it:
mainWindow.webContents.on("did-finish-load", () => {
test()
})
Post a Comment for "How Can I Get Chrome's Remote Debug URL When Using The "remote-debugging-port" In Electron?"