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]: WebSocket route does not handle full URLs in Playwright #33085

Closed
richardforjoejnr opened this issue Oct 14, 2024 · 0 comments · Fixed by #33095
Closed

[Bug]: WebSocket route does not handle full URLs in Playwright #33085

richardforjoejnr opened this issue Oct 14, 2024 · 0 comments · Fixed by #33095
Assignees
Labels

Comments

@richardforjoejnr
Copy link

Version

1.48.0

Steps to reproduce

Pre-req: Ensure you have playwright repo already setup

  1. Use page.routeWebSocket() to intercept a WebSocket URL
  2. Add the below test and run it
test('intercepted websocket', async ({ page }) => {
        await page.routeWebSocket('wss://echo.websocket.org/', ws => {
            ws.onMessage(message => {
                if (message === 'Hello chatbot') {
                    ws.send('Intercepted Hello chatbot');  // Intercept and modify the response.
                } else {
                    ws.send(message);  // Echo the received message otherwise.
                }
            });
        });

        // Navigate to the WebSocket page
        await page.goto('https://echo.websocket.org/.ws');

        // Interact with the page's UI to send a WebSocket message
        await page.getByRole('button', { name: 'Pause Messaging' }).click();  // Clicking a button.
        await page.locator('#content').fill('Hello chatbot');  // Filling input with a message.
        await page.getByRole('button', { name: 'Send Message' }).click();  // Sending the message.

        // Assert that the console has the expected text
        await expect(page.locator('#console div')).toHaveText(['attempting to connect']);
    });

Expected behavior

I was expecting to see "Intercepted Hello chatbot" shown

I was also expecting the following to work but it didn't

await page.routeWebSocket('/echo.websocket.org/'...

Actual behavior

Observe that nothing happened. Looks like no intercept occured. This was posted in discord and the following was spotted

mxschmitt —
do you mind filing a bug on GitHub?
Looks like its parsed as glob and the wss:// confuses the matching logic.
to make it work you can do:
await page.routeWebSocket(/echo.websocket.org/, ws => {

This worked after making the above change

Additional context

No response

Environment

System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M3 Pro
Memory: 56.78 MB / 18.00 GB
Binaries:
Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
IDEs:
VSCode: 1.93.1 - /usr/local/bin/code
Languages:
Bash: 3.2.57 - /bin/bash
npmPackages:
@playwright/test: ^1.48.0 => 1.48.0

@dgozman dgozman self-assigned this Oct 14, 2024
@dgozman dgozman added the v1.48 label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants