mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 13:45:36 +03:00
chore: deflate large web socket messages (#26720)
This commit is contained in:
parent
feac31dbdc
commit
bc1f6272d8
@ -28,6 +28,7 @@ import type { AndroidDevice } from '../server/android/android';
|
||||
import type { SocksProxy } from '../common/socksProxy';
|
||||
import { debugLogger } from '../common/debugLogger';
|
||||
import { createHttpServer } from '../utils';
|
||||
import { perMessageDeflate } from '../server/transport';
|
||||
|
||||
let lastConnectionId = 0;
|
||||
const kConnectionSymbol = Symbol('kConnection');
|
||||
@ -82,7 +83,11 @@ export class PlaywrightServer {
|
||||
});
|
||||
|
||||
debugLogger.log('server', 'Listening at ' + wsEndpoint);
|
||||
this._wsServer = new wsServer({ server, path: this._options.path });
|
||||
this._wsServer = new wsServer({
|
||||
server,
|
||||
path: this._options.path,
|
||||
perMessageDeflate,
|
||||
});
|
||||
const browserSemaphore = new Semaphore(this._options.maxConnections);
|
||||
const controllerSemaphore = new Semaphore(1);
|
||||
const reuseBrowserSemaphore = new Semaphore(1);
|
||||
@ -92,6 +97,7 @@ export class PlaywrightServer {
|
||||
});
|
||||
}
|
||||
this._wsServer.on('connection', (ws, request) => {
|
||||
debugLogger.log('server', 'Connected client ws.extension=' + ws.extensions);
|
||||
const url = new URL('http://localhost' + (request.url || ''));
|
||||
const browserHeader = request.headers['x-playwright-browser'];
|
||||
const browserName = url.searchParams.get('browser') || (Array.isArray(browserHeader) ? browserHeader[0] : browserHeader) || null;
|
||||
|
@ -23,6 +23,16 @@ import { makeWaitForNextTask } from '../utils';
|
||||
import { httpHappyEyeballsAgent, httpsHappyEyeballsAgent } from '../utils/happy-eyeballs';
|
||||
import type { HeadersArray } from './types';
|
||||
|
||||
export const perMessageDeflate = {
|
||||
zlibDeflateOptions: {
|
||||
level: 3,
|
||||
},
|
||||
zlibInflateOptions: {
|
||||
chunkSize: 10 * 1024
|
||||
},
|
||||
threshold: 10 * 1024,
|
||||
};
|
||||
|
||||
export type ProtocolRequest = {
|
||||
id: number;
|
||||
method: string;
|
||||
@ -117,13 +127,13 @@ export class WebSocketTransport implements ConnectionTransport {
|
||||
this.wsEndpoint = url;
|
||||
this._logUrl = logUrl;
|
||||
this._ws = new ws(url, [], {
|
||||
perMessageDeflate: false,
|
||||
maxPayload: 256 * 1024 * 1024, // 256Mb,
|
||||
// Prevent internal http client error when passing negative timeout.
|
||||
handshakeTimeout: Math.max(progress?.timeUntilDeadline() ?? 30_000, 1),
|
||||
headers,
|
||||
followRedirects,
|
||||
agent: (/^(https|wss):\/\//.test(url)) ? httpsHappyEyeballsAgent : httpHappyEyeballsAgent
|
||||
agent: (/^(https|wss):\/\//.test(url)) ? httpsHappyEyeballsAgent : httpHappyEyeballsAgent,
|
||||
perMessageDeflate,
|
||||
});
|
||||
this._ws.on('upgrade', response => {
|
||||
for (let i = 0; i < response.rawHeaders.length; i += 2) {
|
||||
|
Loading…
Reference in New Issue
Block a user