question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pptr connect with electron failed

See original GitHub issue

environment:

  • Puppeteer version: 1.6.2
  • Platform / OS version: win10 electron 4.0.1
  • Node.js version: 10.11.0

description

Because electron app is a chromium, so I want to use puppeteer.connect() connect with electron. I already set electron’s chromium with --remote-debugging-port=9223. when electron started, I open http://localhost:9223/json/version, can get :

{
   "Browser": "Chrome/69.0.3497.106",
   "Protocol-Version": "1.3",
   "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.106 Electron/4.0.1 Safari/537.36",
   "V8-Version": "6.9.427.24",
   "WebKit-Version": "537.36 (@857b284701ddf7bef0f14fa76416cf7ca786b411)",
   "webSocketDebuggerUrl": "ws://localhost:9223/devtools/browser/xxxxxxx"
}

Then, I use webSocketDebuggerUrl set to connect() args :

puppeteer.connect({
	browserWSEndpoint: "ws://localhost:9223/devtools/browser/xxxxxxx"
}).then(async browser => {
	const page = await browser.newPage();
}).catch(e => {
	console.log(e)
})

when I run this script, log error :

{ Error: Protocol error (Target.getBrowserContexts): Not supported
    at Promise (C:\WorkSpace\test\pptr-test\node_modules\puppeteer\lib\Connection.js:86:56)
    at new Promise (<anonymous>)
    at Connection.send (C:\WorkSpace\test\pptr-test\node_modules\puppeteer\lib\Connection.js:85:12)
    at Function.connect (C:\WorkSpace\test\pptr-test\node_modules\puppeteer\lib\Launcher.js:257:50)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  message: 'Protocol error (Target.getBrowserContexts): Not supported' }

Then I try other different version puppeteer, but also log above error. Include puppeteer@1.6.x that support chromium’s version equal 69.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
abinavseelancommented, Apr 3, 2019

Trying to achieve the same thing and running into the same issue. 😕

Here’s a demo snippet

const { app, BrowserWindow } = require('electron');
const request = require('axios');
const puppeteer = require('puppeteer-core');

let mainWindow;
app.commandLine.appendSwitch('remote-debugging-port', '9222');

async function createWindow() {
    const response = await request.get('http://localhost:9222/json/version');

    mainWindow = new BrowserWindow({
        width: 1280,
        height: 720,
    });

    mainWindow.on('closed', () => {
        mainWindow = null;
    });

    puppeteer
        .connect({
            browserWSEndpoint: response.data.webSocketDebuggerUrl,
        })
        .then(async (browser) => {
            const page = await browser.newPage();
            await page.goto('https://google.com');
        })
        .catch((err) => {
            console.log(err);
        });
}
5reactions
aslushnikovcommented, Apr 13, 2019

@LarenDorr Electron is a custom embedder - and a few DevTools protocol methods are expected to be implemented in an embedder. One of these methods is Target.getBrowserContexts. Until electron supports it upstream, Puppeteer’s browser contexts won’t work with electron.

As a workaround, you can try using Puppeteer v1.4.0.

We, however, can make it mostly work with Electron - things like clicking, typing and navigations should be working just fine. Closing this in favor of https://github.com/GoogleChrome/puppeteer/issues/4283 - there’s some more context. Let’s continue discussion there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Failed to launch the browser process puppeteer
I had the same issue, I tried everything which is listed from the Puppeteer guide, none of them worked for me.
Read more >
Supported Command Line Switches - Electron
Command line switches supported by Electron. You can use app.commandLine.appendSwitch to append them in your app's main script before the ready event of...
Read more >
All the Electron Docs! | Electron
Returns String - A path to a special directory or file associated with name . On failure an Error is thrown. You can...
Read more >
webContents | FAQ - GitHub Pages
This event is like did-finish-load but emitted when the load failed or was cancelled, ... status indicates the socket connection to download the...
Read more >
@elavoie/electron-webrtc - npm
Use WebRTC in Node.js via a hidden Electron process. ... errors that may occur when trying to communicate with Electron wrtc.on('error', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found