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

[BUG] WebSocketRoute not working properly #31

Open
1 task done
josegrobles opened this issue Dec 29, 2024 · 4 comments
Open
1 task done

[BUG] WebSocketRoute not working properly #31

josegrobles opened this issue Dec 29, 2024 · 4 comments
Assignees
Labels
bug Something isn't working detection related to bot detection enhancement New feature or request

Comments

@josegrobles
Copy link

josegrobles commented Dec 29, 2024

System info

  • Playwright Version: 1.49.1
  • Operating System: All
  • Browser: Chrome

Source code

const { chromium } = require('patchright');

(async () => {
  const browser = await chromium.launch({
    headless: false,
    viewport: null,
    channel: 'chrome',
  });
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.routeWebSocket(() => true, ws => {
    const server = ws.connectToServer();
    ws.onMessage(message => {
      console.log('sent',message);
      server.send(message);
    });
    server.onMessage(message => {
      console.log('received',message);
      ws.send(message);
    });
  });

  await page.goto('https://www.olybet.ee/sports/live');
})();
  • I provided exact source code that allows reproducing the issue locally.

Steps

  • Run the provided Script

Expected

Logs all the messages from WebSocket connections on the current page.

Actual

Nothing is logged. If you try with the regular Playwright it works properly.

@josegrobles josegrobles changed the title [BUG] [BUG] WebSocketRoute not working properly Dec 29, 2024
@Vinyzu Vinyzu self-assigned this Dec 29, 2024
@ramsestom
Copy link

ramsestom commented Jan 29, 2025

WebSocketRoute rely on bindings through Runtime.addBinding to transmit the websocket messages received from a server and captured/modified by the webSocketMock injected proxy (injected with an InitScript on each page) back to playwright. As patchright removed all Runtime.enable calls from the playwright code, I think this might be the issue if bindings created by calls to the Runtime domain have to have that domain enabled to work

@kaliiiiiiiiii
Copy link
Collaborator

injected proxy (injected with an InitScript on each page)

I believe removing this is intentional, since applying JS proxies is genrally detectable. The way to go here would be to use a mitmproxy. Eg. smth compareable to https://github.com/ulixee/hero/blob/2ef172222db080368a0897e3eac39fa91c6598fe/agent/docs/Man-in-the-Middle.md

I guess this is in our TODO's at some point - but probably not any near time.

@kaliiiiiiiiii kaliiiiiiiiii added bug Something isn't working detection related to bot detection enhancement New feature or request labels Jan 30, 2025
@ramsestom
Copy link

ramsestom commented Jan 30, 2025

I believe removing this is intentional, since applying JS proxies is genrally detectable.

The whole playwright api is an injected JS script. Locators all run with a JS script injected by playwright on every page for example. So the JS webSocketMock proxy isn't the only JS playwright inject to work.

@kaliiiiiiiiii
Copy link
Collaborator

kaliiiiiiiiii commented Jan 31, 2025

I believe removing this is intentional, since applying JS proxies is genrally detectable.

The whole playwright api is an injected JS script. Locators all run with a JS script injected by playwright on every page for example. So the JS webSocketMock proxy isn't the only JS playwright inject to work.

Here it is, actually, since patchright executes all other stuff in an isolated world

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working detection related to bot detection enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants