cypress-har-generator icon indicating copy to clipboard operation
cypress-har-generator copied to clipboard

Error: Failed to connect to Chrome Debugging Protocol

Open nfelger opened this issue 2 years ago • 3 comments

Running the plugin out-of-the-box on macOS, I get this error:

$ npx cypress run --config baseUrl=https://my.domain --browser chrome

From Node.js Internals:
    Error: Failed to connect to Chrome Debugging Protocol
    
    Common situations why this would fail:
      - you forgot to run Chrome in headless mode
      - you use Chrome version 58 or earlier
      - you have weird RDP configuration settings
      
    The stack trace for this error is:
        at t.CRIConnection.<anonymous> (/Users/nfelger/Dropbox/dev/projects/myproj/test/load/node_modules/@neuralegion/cypress-har-generator/dist/webpack:/@neuralegion/cypress-har-generator/src/cdp/CRIConnection.ts:37:27)
    at Generator.next (<anonymous>)
        at fulfilled (/Users/nfelger/Dropbox/dev/projects/myproj/test/load/node_modules/tslib/tslib.js:115:62)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)

Versions:

Cypress:        9.6.1
Browser:        Chrome 101 (headless)
Node Version:   v17.8.0 (/usr/local/Cellar/node/17.8.0/bin/node)
macOS:          12.2.1
@neuralegion/cypress-har-generator: 5.3.0

My Cypress test:

describe("static pages", () => {
  before(() => {
    // start recording
    cy.recordHar();
  });

  after(() => {
    cy.saveHar();
  });

  it("Home page", () => {
    cy.visit("/");
  });
});

Poking around in logs and code a bit, it seems like Chrome is started with --remote-debugging-address=127.0.0.1 but cypress-har-generator tries to access it on ::1, which Chrome isn't listening on.

I can fix this for me by changing https://github.com/NeuraLegion/cypress-har-generator/blob/1188c09df99958f77d35c79d7fe1717bb5c9fbdd/src/Plugin.ts#L54 to:

{ host: "127.0.0.1", port: this.rdpPort },

But I'm not sure if that's the right way to go about it?

nfelger avatar May 22 '22 20:05 nfelger

I have the same issue on Arch Linux, unfortunately I was not able to fix it like you, but when I added debugging address as a launch option like:

on("before:browser:launch", (browser = {}, launchOptions) => {
		ensureBrowserFlags(browser, launchOptions);
		launchOptions.args.push("--remote-debugging-address=::1");
		return launchOptions;
	});
};

The error changed to:

Still waiting to connect to Chromium, retrying in 1 second (attempt 18/62)
...
Still waiting to connect to Chromium, retrying in 1 second (attempt 62/62)
Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 50 seconds.

This usually indicates there was a problem opening the Chromium browser.

The CDP port requested was 33847.

Error: connect ECONNREFUSED 127.0.0.1:33847
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)

michailspiridonov avatar May 31 '22 14:05 michailspiridonov

Having this same issue and I can't even figure out how to alter it. Does this plugin not work when running tests against localhost?

JonTheStone avatar Jul 25 '22 21:07 JonTheStone

I encountered the same problem. But only after installing a new Node version. It works fine in 16.17.0, but in 18.7.0 the problem started to happen for me. So for now I'm back to 16.17.0

jdvegmond avatar Aug 19 '22 06:08 jdvegmond

I encountered the same problem. But only after installing a new Node version. It works fine in 16.17.0, but in 18.7.0 the problem started to happen for me. So for now I'm back to 16.17.0

Downgrading node solved the issue, thanks!

michailspiridonov avatar Sep 05 '22 11:09 michailspiridonov

Hi @nfelger, Thanks for the report. unfortunately, I'm not able to reproduce the same behavior using Node.js 14, 16, or 18 on macOS. Anyway, I'm going to specify a host according to arguments passed by Cypress. Let's check if it works for you.

derevnjuk avatar Sep 07 '22 21:09 derevnjuk