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

throwing ws error after upgrading ws version #372

Closed
hbakhtiyor opened this issue Nov 3, 2018 · 13 comments
Closed

throwing ws error after upgrading ws version #372

hbakhtiyor opened this issue Nov 3, 2018 · 13 comments

Comments

@hbakhtiyor
Copy link
Contributor

i use upstream master, and getting error after this commit 4b8dcee

Error: Unexpected server response: 404
    at ClientRequest.req.on (/demor/node_modules/chrome-remote-interface/node_modules/ws/lib/websocket.js:535:5)
    at ClientRequest.emit (events.js:182:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:546:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at TLSSocket.socketOnData (_http_client.js:432:20)
    at TLSSocket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at TLSSocket.Readable.push (_stream_readable.js:219:10)
    at TLSWrap.onread (net.js:638:20)
@cyrus-and
Copy link
Owner

Doing what exactly...?

@hbakhtiyor
Copy link
Contributor Author

during creating new tab, i think it throws for any samples

@cyrus-and
Copy link
Owner

I cannot reproduce this. Please try to come up with a minimal standalone example that cases this issue.

@hbakhtiyor
Copy link
Contributor Author

for example,

const CDP = require('chrome-remote-interface');

async function navigateInANewTab(url) {
    const options = { host: 'host', port: 443, secure: true, useHostName: true, local: false };
    const tab = await CDP.New(options);
    const client = await CDP(Object.assign(options, {tab}));
    await CDP.Close(Object.assign(options, {id: tab.id}));
}

navigateInANewTab('https://github.com');

@cyrus-and
Copy link
Owner

Is it reproducible even without secure and useHostName?

@hbakhtiyor
Copy link
Contributor Author

i can't reproduce it locally without these options

@cyrus-and
Copy link
Owner

OK so I tried with an nginx reverse proxy in a Docker container where 172.17.0.1 is the host running Chrome:

server {
    listen 443;
    ssl on;
    ssl_certificate     /etc/nginx/cert.pem;
    ssl_certificate_key /etc/nginx/key.pem;

    location / {
        proxy_http_version 1.1;
        proxy_pass         http://172.17.0.1:9222;
    }

    location /devtools/ {
        proxy_http_version 1.1;
        proxy_pass     http://172.17.0.1:9222;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

DevTools methods (new tab, protocol, list, etc.) work as expected, WebSocket inspection only works if the right hostname is used manually, meaning that the WebSocket addresses returned by Chrome are like:

ws://172.17.0.1:9222/devtools/page/68EF5E725DFE76CEEBEE6E4CAF105A11

While the request is performed with (example.com points to 127.0.0.1):

curl -k https://example.com/json/list

I wonder what's your use case if you're not affected with the above...

Maybe I should replace the host:port part with the one of the original request when useHostName is true.


In any case I'm unable to reproduce your issue...

@hbakhtiyor
Copy link
Contributor Author

sent message to your email

@cyrus-and
Copy link
Owner

Hi sorry for the late reply (and thanks for the email) so apparently this is either a bug in ws or your backend because even using wscat fails with 404:

wscat -c wss://YOURBACKEND/devtools/page/3103E3E5955B472A4FDC9DCEE7AC817A

But as you say, the fact is that old versions of ws work... let me try to debug it.

@cyrus-and
Copy link
Owner

OK so the difference is in the port of the host header of the request:

  • Response HTTP/1.0 404 The page you're looking for doesn't exist., host header field in request:

      Host: YOURBACKEND:443
    
  • Response HTTP/1.1 101 WebSocket Protocol Handshake, host header field in request:

      Host: YOURBACKEND
    

Also note the HTTP version. I suspect this is a bug in your backend, double check you configuration and let me know.

@paambaati
Copy link
Contributor

As a heads up, most HTTP clients (curl, Chrome, Firefox, ruby, AsyncHttpClient for Scala, and recently request for Node) have started dropping the port suffix from the header. This is still RFC compliant.

This thread includes a few relevant links - request/request#2894

@cyrus-and
Copy link
Owner

@paambaati thanks but in this case the scenario is the opposite: ws omitted the port and only recently it started to add it.

@cyrus-and
Copy link
Owner

Well, that's the reason; I'm closing this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants