Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: fix the android ws sender/receiver (#13641)

Pavel Feldman06645b0a1ff5
diff --git a/packages/playwright-core/bundles/utils/src/utilsBundleImpl.ts b/packages/playwright-core/bundles/utils/src/utilsBundleImpl.ts
index 6ce937ae20..1ec3c810a7 100644
--- a/packages/playwright-core/bundles/utils/src/utilsBundleImpl.ts
+++ b/packages/playwright-core/bundles/utils/src/utilsBundleImpl.ts
@@ -54,6 +54,9 @@ export { SocksProxyAgent } from 'socks-proxy-agent';
import StackUtilsLibrary from 'stack-utils';
export const StackUtils = StackUtilsLibrary;
-import wsLibrary, { WebSocketServer } from 'ws';
+// @ts-ignore
+import wsLibrary, { WebSocketServer, Receiver, Sender } from 'ws';
export const ws = wsLibrary;
export const wsServer = WebSocketServer;
+export const wsReceiver = Receiver;
+export const wsSender = Sender;
diff --git a/packages/playwright-core/src/server/android/android.ts b/packages/playwright-core/src/server/android/android.ts
index 6216c06dd9..d8e46cbc41 100644
--- a/packages/playwright-core/src/server/android/android.ts
+++ b/packages/playwright-core/src/server/android/android.ts
@@ -21,7 +21,7 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import type * as stream from 'stream';
-import { ws } from '../../utilsBundle';
+import { wsReceiver, wsSender } from '../../utilsBundle';
import { createGuid, makeWaitForNextTask, isUnderTest } from '../../utils';
import { removeFolders } from '../../utils/fileUtils';
import type { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser';
@@ -418,7 +418,7 @@ class AndroidBrowser extends EventEmitter {
this.onclose();
});
});
- this._receiver = new (ws as any).Receiver() as stream.Writable;
+ this._receiver = new wsReceiver() as stream.Writable;
this._receiver.on('message', message => {
this._waitForNextTask(() => {
if (this.onmessage)
@@ -452,7 +452,7 @@ Sec-WebSocket-Version: 13\r
}
function encodeWebFrame(data: string): Buffer {
- return (ws as any).Sender.frame(Buffer.from(data), {
+ return wsSender.frame(Buffer.from(data), {
opcode: 1,
mask: true,
fin: true,
diff --git a/packages/playwright-core/src/utilsBundle.ts b/packages/playwright-core/src/utilsBundle.ts
index db4b457ddb..e47b55c3e1 100644
--- a/packages/playwright-core/src/utilsBundle.ts
+++ b/packages/playwright-core/src/utilsBundle.ts
@@ -31,5 +31,7 @@ export const SocksProxyAgent: typeof import('../bundles/utils/node_modules/socks
export const StackUtils: typeof import('../bundles/utils/node_modules/@types/stack-utils') = require('./utilsBundleImpl').StackUtils;
export const ws: typeof import('../bundles/utils/node_modules/@types/ws') = require('./utilsBundleImpl').ws;
export const wsServer: typeof import('../bundles/utils/node_modules/@types/ws').WebSocketServer = require('./utilsBundleImpl').wsServer;
+export const wsReceiver = require('./utilsBundleImpl').wsReceiver;
+export const wsSender = require('./utilsBundleImpl').wsSender;
export type { Command } from '../bundles/utils/node_modules/commander';
export type { WebSocket, WebSocketServer, RawData as WebSocketRawData, EventEmitter as WebSocketEventEmitter } from '../bundles/utils/node_modules/@types/ws';