[英]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: 我在Electron主程序中为Chrome设置了
remote-debugging-port
选项:
app.commandLine.appendSwitch('remote-debugging-port', '8315')
Now, how can I get the ws://
URL that I can use to connect to Chrome? 现在,我如何获得可用于连接Chrome的
ws://
URL?
I see that the output while I'm running Electron shows 我看到运行Electron时的输出显示
DevTools listening on ws://127.0.0.1:8315/devtools/browser/52ba17be-0c0d-4db6-b6f9-a30dc10df13c
but I would like to get this URL from inside the main process. 但是我希望从主进程中获取此URL。 The URL is different every time.
URL每次都不同。 How can I get it from inside the Electron main process?
如何从Electron主流程中获取它?
Can I somehow read my Electron's main process output, from within my main process JavaScript code? 我可以以某种方式从我的主进程JavaScript代码中读取我的Electron的主进程输出吗?
Here's how to connect Puppeteer to your Electron window from your Electron main process code: 以下是如何通过Electron主流程代码将Puppeteer连接到Electron窗口:
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()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.