This is more of an implmentation question. I have a page which connects to a websocket server on page load.
I am able to handle the websocket connection on the website with Playwright in JAVA using the following pseudo code
public static void main()
{
//some code
page.onWebSocket(ws->{
test(ws);
});
//some code
}
public void test(WebSocket ws)
{
System.out.println("Websocket Opened "+ws.url());
ws.onFrameSent(ws1160454->{frameSent(ws1160454);});
ws.onFrameReceived(ws1160455->{processData(ws1160455);});
}
However on the same page, when a button is clicked a new second websocket connection to a different URL is triggered. I am able to click the button and the browser is showing the data from the second websocket, however the new websocket connection is not triggering the test method again. I even duplicated the handler method.
public static void main()
{
//some code
page.onWebSocket(ws->{
test(ws);
});
// some code
page.onWebSocket(ws2->{
test2(ws2);
});
}
public void test2(WebSocket ws2)
{
System.out.println("Websocket Opened "+ws2.url());
ws.onFrameSent(ws1160464->{frameSent(ws1160464);});
ws.onFrameReceived(ws1160465->{processData(ws1160465);});
}
` What am I missing?
The first websocket connection works and the callbacks are handling the data, the second websocket even though is open and the browser is showing the data, doesn't even print the websocket opened message.