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.

[BUG] Proxying WebSockets with http-proxy not working with firefox and webkit

See original GitHub issue

Context:

  • Playwright Version: [^0.11.1]
  • Operating System: [Windows 10]
  • Extra: [Using docker to launch playwright server ]

Code Snippet

playwright-docker-server

Describe the bug

I am trying to dockerized the playwright to launch a server inside the docker and proxy the socket as follow:

import * as httpProxy from 'http-proxy';
import * as playwright from 'playwright';

const proxy = httpProxy.createProxyServer();
http
  .createServer()
  .on('upgrade', async (req, socket, head) => {
    const browser = await playwright['chromium'].launchServer({
      args: ['--no-sandbox'],
    });
    const endPoint = browser.wsEndpoint();
    proxy.ws(req, socket, head, {target: endPoint });
  })
  .on('listening', () => {
    console.log('Server listening...');
  })
  .on('close', () => {
    console.log('http server closed');
  })
  .listen(3000);

The above code works well with chrome, however, it won’t work with WebKit and firefox.

It throws following error for firefox:

(node:25528) UnhandledPromiseRejectionWarning: Error: WebSocket error: Unexpected server response: 400
    at WebSocket._ws.addEventListener.event (\node_modules\playwright-core\lib\platform.js:288:65)
    at WebSocket.onError (\node_modules\playwright-core\node_modules\ws\lib\event-target.js:128:16)
    at WebSocket.emit (events.js:194:15)
    at abortHandshake (\node_modules\playwright-core\node_modules\ws\lib\websocket.js:718:15)
    at ClientRequest.req.on (\node_modules\playwright-core\node_modules\ws\lib\websocket.js:595:7)
    at ClientRequest.emit (events.js:189:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at Socket.socketOnData (_http_client.js:442:20)
    at Socket.emit (events.js:189:13)
(node:25528) UnhandledPromiseRejectionWarning: Error: Protocol error (Target.enable): Target closed.
    at Promise (\node_modules\playwright-core\lib\firefox\ffConnection.js:54:63)
    at new Promise (<anonymous>)
    at FFConnection.send (\node_modules\playwright-core\lib\firefox\ffConnection.js:53:16)
    at Function.connect (\node_modules\playwright-core\lib\firefox\ffBrowser.js:49:26)
    at Firefox.connect (\node_modules\playwright-core\lib\server\firefox.js:132:38)
    at \src\main.ts:5:49
    at Generator.next (<anonymous>)
    at \node_modules\tslib\tslib.js:110:75
    at new Promise (<anonymous>)
    at Object.__awaiter (\node_modules\tslib\tslib.js:106:16)

And following error for WebKit:

 UnhandledPromiseRejectionWarning: Error: Protocol error (Browser.createContext): Browser has been closed.
    at Promise (\node_modules\playwright-core\lib\webkit\wkConnection.js:99:63)
    at new Promise (<anonymous>)
    at WKSession.send (\node_modules\playwright-core\lib\webkit\wkConnection.js:98:16)
    at WKBrowser.newContext (\node_modules\playwright-core\lib\webkit\wkBrowser.js:57:65)
    at WKBrowser.<anonymous> (\node_modules\playwright-core\lib\helper.js:55:31)
    at \src\main.ts:9:33
    at Generator.next (<anonymous>)
    at fulfilled (\node_modules\tslib\tslib.js:107:62)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
  -- ASYNC --
    at WKBrowser.<anonymous> (\node_modules\playwright-core\lib\helper.js:54:23)
    at \src\main.ts:9:33
    at Generator.next (<anonymous>)
    at fulfilled (\node_modules\tslib\tslib.js:107:62)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Not sure if this problem is related to #810, feel free to close this issue if it’s same.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arjunattamcommented, Feb 26, 2020

Thanks @cyrus-d for reporting this. This implies that the system dependencies for the browsers are not installed in the docker image. To debug this, you can use dumpio: true in the launch() method arguments.

On looking at the dockerfile in playwright-docker-server repo, I can see some missing dependencies. You can refer to this working image for Ubuntu 18.04.

We are working on fixing the troubleshooting docs, and adding working dockerfile definitions

0reactions
ccpucommented, Feb 27, 2020

@arjun27 thanks for the dockerfile it has solved my problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

websocket doesn't work if firefox uses the system's proxy ...
Using the http_proxy and https_proxy environment variables instead of the Gnome proxy settings leads to the same problem. If we configure the HTTP...
Read more >
websocket connects to DIRECT instead of Proxy-HTTP/HTTPS ...
Connection should go into the proxy. I tried with a PAC file and Manual proxy, there's no bug. Only with the "Use System...
Read more >
1655372 - Websockets fails to connect and enters a ...
Regular HTTP and HTTPS pages load fine with the same HTTP/2 TLS proxy, it's only WebSockets that don't work. The same problem occurs...
Read more >
1517782 - Firefox 65 websocket via proxy not working
Setup some forwarding proxy server (tested Apache/2.4.37, tinyproxy 1.10.0) within Firefox with using for all protocols. 3. Go to address https://doozer.io/ ...
Read more >
Websockets should prioritize SOCKS5 proxies over HTTP(S ...
Firefox should use the SOCKS5 proxy. From RFC 6455, Section 4.1, requirement 3, page 15: "NOTE: Implementations that do not expose explicit UI...
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