cypress-audit
cypress-audit copied to clipboard
cy.pa11y() fails with "Failed to fetch browser webSocket URL from http://localhost:65406/json/version"
What does not work? When I try to run the cy.pa11y() command it always fails with
Failed to fetch browser webSocket URL from http://localhost:65406/json/version: request to http://localhost:65406/json/version failed, reason: connect ECONNREFUSED ::1:65406
How to reproduce? I followed the set up from https://mfrachet.github.io/cypress-audit/ I also pulled this repo and tried the examples but I get the same issue no matter what site I am trying to run pa11y against.
Expected behavior Pa11y is run
Screenshots / Animated Gifs
Environment (please complete the following information):
- OS: MacOS Monterey 12.4
- Chrome version: 103.0.5060.114
- Cypress version: 10.3.0
I honestly don't know what's happening here, pa11y runs locally for me on the project you're trying to run:

Do you run on a specific machine / configuration?
I just pulled the project to my personal PC running Windows and it worked. I believe IT might be managing my work MacBook, maybe they've blocked something. Do you have any ideas what could cause the issue? I'll ask the IT guys if they know anything :)
Is it possible to set which port Pa11y is using? I can see for lighthouse I can pass opts and configs when calling but I can't see any documentation to do the same for pa11y on cypress-audit Documentation
I was facing this same issue. After adding logs I came to know that the issue was coming from this method call where the library is using puppeteer to connect to the browser.
In my case, I was running the cypress server from a docker container and spawning the browser on the host machine. This means that there are two separate networks here. So for the code localhost was docker's network and not the host machine's network. We fixed it by changing the localhost as shown here.
So please check if localhost is being resolved or not in your case.
Is it possible to set which port Pa11y is using?
Do you mean the remote debugging port? If yes then you can set the CYPRESS_REMOTE_DEBUGGING_PORT
env variable to tell cypress to use that port as the remote debugging port before launching the browser as shown here. This library will read that port's value as per the code written here.
Thanks for the reply @pranavj1001, unfortunately it's not a localhost issue for me, I get the same issue on any site I try to use Pa11y on.
It seems to be related to my work laptop, a few of us can run the code fine on our personal machines but not on our work assigned devices.
I did try changing the remote debugging port but there's an open issue with Cypress that stops it working https://github.com/cypress-io/cypress/issues/21167
So please check if localhost is being resolved or not in your case.
Hey @MichaelRobsonSliide, by localhost issue I did not mean the site on which you're trying to use pa11y. By localhost, I meant the hardcoded URL that is written here. This URL is used to connect to the browser.
I'm not sure what I would change that too, I tried my local IP address and some different ports instead of localhost but I still get the same. The app I'm trying to test is running locally on my laptop.
If I use pa11y through command line it works fine it's just when I try to use it on this laptop through cypress-audit that I get the error.
Hey @MichaelRobsonSliide and @mfrachet, I was facing the exact same issue and was really confused why this was no longer working, since it had already worked for me. As I was browsing through the issues I came across an older Issue that was closed, where someone mentioned that this problem might be caused when using Node.js 17+ (https://github.com/mfrachet/cypress-audit/issues/136#issuecomment-1309782188). When it was working before, I was using a lower version and upgraded later on for some other tools. I think that is also the reason why you @mfrachet were not able to reproduce it and why you @MichaelRobsonSliide had the issue fixed somehow, when working on another machine. Therefore, I would suggest either stating somewhere that the Node.js version must be below 17 or fixing the issue. (Instead of downgrading the Version I used the same workaround presented by RJKeane2000 in that comment and @pranavj1001 in this discussion.)
I am having the same issue
`has no detectable a11y violations on load (pa11y)failed BEFORE EACH 1 visit/home (xhr)GET 200 /assets/markdown/view-home/view-home.md TEST BODY 1 url 2 taskpa11y, {url: http://localhost:4200/home, opts: {standard: WCAG2AAA}} CypressError cy.task('pa11y') failed with the following error:
Failed to fetch browser webSocket URL from http://localhost:1189/json/version: request to http://localhost:1189/json/version failed, reason: connect ECONNREFUSED ::1:1189Learn more ../../node_modules/@cypress-audit/pa11y/src/command-handler.js:69:1 67 | return cy 68 | .url() 69 | .then((url) => cy.task("pa11y", { url, opts })) | ^ 70 | .then((issues) => { 71 | if (issues.length > 0) { 72 | const groupedIssues = groupIssues(issues); View stack trace`