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]: The routeWebSocket does not work on subsequent attempts unless the browser window is closed. #34045

Open
terradek opened this issue Dec 17, 2024 · 0 comments
Assignees
Labels

Comments

@terradek
Copy link

Version

1.49.1

Steps to reproduce

Code_3OaThBCe03.mp4
    // Set up WebSocket interception before clicking Update Device
    await page.routeWebSocket(/.+\/v2/, async route => {
      console.log('routeWebSocket entered');

      const server = route.connectToServer(); // Connect to the actual server
      console.log('Server message: routeWebSocket');

      // Messages from page to server are forwarded automatically
      // We only need to handle server-to-page messages that need modification
      server.onMessage(message => {
        const msgObj = JSON.parse(message);
        console.log('Server message:', message);

        // Check if this is a device status message that needs modification
        if (msgObj?.payload?.data?.DeviceChanged?.DevStatus === 'Disconnected') {
          msgObj.payload.data.DeviceChanged.DevStatus = 'Connected';
          console.log('Modified to:', JSON.stringify(msgObj));
          message = JSON.stringify(msgObj);
        }
        route.send(message);// Send either modified or original message
      });
    });

Expected behavior

It should work regardless of the closed Browser window.

Actual behavior

routeWebSocket fails to intercept the ws. Please check the screencast attached.

Additional context

No response

Environment

System:
    OS: Windows 11 10.0.26100
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 8.10 GB / 31.73 GB
  Binaries:
    Node: 22.5.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    VSCode: 1.96.0 - C:\Progs\Microsoft VS Code\bin\code.CMD
@terradek terradek changed the title [Bug]: routeWebSocket is not working if the browser window is not closed [Bug]: The routeWebSocket does not work on subsequent attempts unless the browser window is closed. Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants