Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cy.pa11y() fails with "Failed to fetch browser webSocket URL from http://localhost:65406/json/version" #172

Open
MichaelRobsonSliide opened this issue Jul 7, 2022 · 9 comments
Labels
bug Something isn't working

Comments

@MichaelRobsonSliide
Copy link

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
Screenshot 2022-07-07 at 17 53 21

Environment (please complete the following information):

  • OS: MacOS Monterey 12.4
  • Chrome version: 103.0.5060.114
  • Cypress version: 10.3.0
@MichaelRobsonSliide MichaelRobsonSliide added the bug Something isn't working label Jul 7, 2022
@mfrachet
Copy link
Owner

mfrachet commented Jul 8, 2022

I honestly don't know what's happening here, pa11y runs locally for me on the project you're trying to run:

Screenshot 2022-07-08 at 07 32 06

Do you run on a specific machine / configuration?

@MichaelRobsonSliide
Copy link
Author

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 :)

@MichaelRobsonSliide
Copy link
Author

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

@pranavj1001
Copy link

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.

@MichaelRobsonSliide
Copy link
Author

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 cypress-io/cypress#21167

@pranavj1001
Copy link

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.

@MichaelRobsonSliide
Copy link
Author

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.

@SCH17044
Copy link

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+ (#136 (comment)). 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.)

@JBusch
Copy link

JBusch commented Oct 5, 2023

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`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants