@vpalmisano/webrtcperf 4.3.2 → 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.min.js +1 -1
- package/build/src/app.js +16 -5
- package/build/src/app.js.map +1 -1
- package/build/src/config.d.ts +1 -0
- package/build/src/config.js +7 -0
- package/build/src/config.js.map +1 -1
- package/build/src/docker.d.ts +1 -0
- package/build/src/docker.js +123 -0
- package/build/src/docker.js.map +1 -0
- package/build/src/session.d.ts +5 -1
- package/build/src/session.js +73 -23
- package/build/src/session.js.map +1 -1
- package/build/src/utils.d.ts +5 -1
- package/build/src/utils.js +22 -14
- package/build/src/utils.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -25
- package/src/app.ts +17 -7
- package/src/config.ts +7 -0
- package/src/docker.ts +131 -0
- package/src/session.ts +66 -15
- package/src/utils.ts +22 -13
package/build/src/session.js
CHANGED
|
@@ -99,6 +99,8 @@ class Session extends events_1.default {
|
|
|
99
99
|
id;
|
|
100
100
|
/** The throttle configuration index assigned to the session. */
|
|
101
101
|
throttleIndex;
|
|
102
|
+
/** If true, the network will be throttled using the browser internal throttling mechanism. */
|
|
103
|
+
useBrowserThrottling;
|
|
102
104
|
/** The test page url. */
|
|
103
105
|
url;
|
|
104
106
|
/** The url query. */
|
|
@@ -152,7 +154,7 @@ class Session extends events_1.default {
|
|
|
152
154
|
});
|
|
153
155
|
constructor({ chromiumUrl, chromiumPath, chromiumFieldTrials, windowWidth, windowHeight, deviceScaleFactor, display,
|
|
154
156
|
/* audioRedForOpus, */
|
|
155
|
-
url, urlQuery, customUrlHandler, customUrlHandlerFn, mediaPath, videoWidth, videoHeight, videoFramerate, useFakeMedia, enableGpu, enableBrowserLogging, startTimestamp, sessions, tabsPerSession, spawnPeriod, statsInterval, disabledVideoCodecs, localStorage, sessionStorage, clearCookies, scriptPath, showPageLog, pageLogFilter, pageLogPath, userAgent, id, throttleIndex, evaluateAfter, exposedFunctions, scriptParams, blockedUrls, extraHeaders, responseModifiers, downloadResponses, extraCSS, cookies, overridePermissions, hardwareConcurrency, debuggingPort, debuggingAddress, randomAudioPeriod, maxVideoDecoders, maxVideoDecodersRange, incognito, serverPort, serverSecret, serverUseHttps, emulateCpuThrottling, }) {
|
|
157
|
+
url, urlQuery, customUrlHandler, customUrlHandlerFn, mediaPath, videoWidth, videoHeight, videoFramerate, useFakeMedia, enableGpu, enableBrowserLogging, startTimestamp, sessions, tabsPerSession, spawnPeriod, statsInterval, disabledVideoCodecs, localStorage, sessionStorage, clearCookies, scriptPath, showPageLog, pageLogFilter, pageLogPath, userAgent, id, throttleIndex, useBrowserThrottling, evaluateAfter, exposedFunctions, scriptParams, blockedUrls, extraHeaders, responseModifiers, downloadResponses, extraCSS, cookies, overridePermissions, hardwareConcurrency, debuggingPort, debuggingAddress, randomAudioPeriod, maxVideoDecoders, maxVideoDecodersRange, incognito, serverPort, serverSecret, serverUseHttps, emulateCpuThrottling, }) {
|
|
156
158
|
super();
|
|
157
159
|
log.debug('constructor', { id });
|
|
158
160
|
this.id = id;
|
|
@@ -230,6 +232,7 @@ class Session extends events_1.default {
|
|
|
230
232
|
this.serverUseHttps = serverUseHttps;
|
|
231
233
|
this.emulateCpuThrottling = emulateCpuThrottling;
|
|
232
234
|
this.throttleIndex = throttleIndex;
|
|
235
|
+
this.useBrowserThrottling = useBrowserThrottling;
|
|
233
236
|
this.evaluateAfter = evaluateAfter || [];
|
|
234
237
|
this.exposedFunctions = exposedFunctions || {};
|
|
235
238
|
if (scriptParams) {
|
|
@@ -405,7 +408,7 @@ class Session extends events_1.default {
|
|
|
405
408
|
deviceScaleFactor: this.deviceScaleFactor,
|
|
406
409
|
isMobile: false,
|
|
407
410
|
hasTouch: false,
|
|
408
|
-
isLandscape:
|
|
411
|
+
isLandscape: true,
|
|
409
412
|
},
|
|
410
413
|
});
|
|
411
414
|
}
|
|
@@ -525,7 +528,7 @@ try {
|
|
|
525
528
|
} catch (err) {
|
|
526
529
|
console.error('[webrtcperf] Error parsing scriptParams:', err);
|
|
527
530
|
webrtcperf.params = {};
|
|
528
|
-
}
|
|
531
|
+
};
|
|
529
532
|
`;
|
|
530
533
|
if (this.serverPort) {
|
|
531
534
|
cmd += `\
|
|
@@ -601,6 +604,8 @@ webrtcperf.config.AUDIO_URL = "http${this.serverUseHttps ? 's' : ''}://localhost
|
|
|
601
604
|
await this.context.overridePermissions(new URL(url).origin, this.overridePermissions);
|
|
602
605
|
}
|
|
603
606
|
const page = await this.getNewPage(tabIndex);
|
|
607
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
608
|
+
const pageCDPSession = page._client();
|
|
604
609
|
await page.setBypassCSP(true);
|
|
605
610
|
if (this.userAgent) {
|
|
606
611
|
await page.setUserAgent(this.userAgent);
|
|
@@ -611,22 +616,28 @@ webrtcperf.config.AUDIO_URL = "http${this.serverUseHttps ? 's' : ''}://localhost
|
|
|
611
616
|
if (this.localStorage) {
|
|
612
617
|
log.debug('Using localStorage:', this.localStorage);
|
|
613
618
|
Object.entries(this.localStorage).map(([key, value]) => {
|
|
614
|
-
cmd += `localStorage.setItem('${key}',
|
|
619
|
+
cmd += `window.localStorage.setItem('${key}', ${JSON.stringify(value)});\n`;
|
|
615
620
|
});
|
|
616
621
|
}
|
|
617
622
|
if (this.sessionStorage) {
|
|
618
623
|
log.debug('Using sessionStorage:', this.sessionStorage);
|
|
619
624
|
Object.entries(this.sessionStorage).map(([key, value]) => {
|
|
620
|
-
cmd += `sessionStorage.setItem('${key}',
|
|
625
|
+
cmd += `window.sessionStorage.setItem('${key}', ${JSON.stringify(value)});\n`;
|
|
621
626
|
});
|
|
622
627
|
}
|
|
628
|
+
cmd += `
|
|
629
|
+
Object.defineProperty(window.screen, 'width', { value: ${this.windowWidth}, writable: false });
|
|
630
|
+
Object.defineProperty(window.screen, 'height', { value: ${this.windowHeight}, writable: false });
|
|
631
|
+
Object.defineProperty(window.screen, 'availWidth', { value: ${this.windowWidth}, writable: false });
|
|
632
|
+
Object.defineProperty(window.screen, 'availHeight', { value: ${this.windowHeight}, writable: false });
|
|
633
|
+
Object.defineProperty(window.screen.orientation, 'type', { value: 'landscape-primary', writable: false });
|
|
634
|
+
`;
|
|
623
635
|
log.debug('init command:', cmd);
|
|
624
636
|
await page.evaluateOnNewDocument(cmd);
|
|
625
637
|
// Clear cookies.
|
|
626
638
|
if (this.clearCookies) {
|
|
627
639
|
try {
|
|
628
|
-
|
|
629
|
-
await client.send('Network.clearBrowserCookies');
|
|
640
|
+
await pageCDPSession.send('Network.clearBrowserCookies');
|
|
630
641
|
}
|
|
631
642
|
catch (err) {
|
|
632
643
|
log.error(`clearCookies error: ${err.stack}`);
|
|
@@ -664,8 +675,6 @@ webrtcperf.config.AUDIO_URL = "http${this.serverUseHttps ? 's' : ''}://localhost
|
|
|
664
675
|
});
|
|
665
676
|
// Enable request interception.
|
|
666
677
|
let setRequestInterceptionState = true;
|
|
667
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
668
|
-
const pageCDPSession = page._client();
|
|
669
678
|
await pageCDPSession.send('Network.setBypassServiceWorker', {
|
|
670
679
|
bypass: true,
|
|
671
680
|
});
|
|
@@ -850,20 +859,25 @@ webrtcperf.config.AUDIO_URL = "http${this.serverUseHttps ? 's' : ''}://localhost
|
|
|
850
859
|
await page.emulateCPUThrottling(this.emulateCpuThrottling);
|
|
851
860
|
}
|
|
852
861
|
// PeerConnectionExternal
|
|
853
|
-
await page.exposeFunction(
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
862
|
+
/* await page.exposeFunction(
|
|
863
|
+
'createPeerConnectionExternal',
|
|
864
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
865
|
+
async (options: any) => {
|
|
866
|
+
const pc = new PeerConnectionExternal(options)
|
|
867
|
+
return { id: pc.id }
|
|
868
|
+
},
|
|
869
|
+
)
|
|
870
|
+
|
|
871
|
+
await page.exposeFunction(
|
|
872
|
+
'callPeerConnectionExternalMethod',
|
|
873
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
874
|
+
async (id: number, name: PeerConnectionExternalMethod, arg: any) => {
|
|
875
|
+
const pc = PeerConnectionExternal.get(id)
|
|
863
876
|
if (pc) {
|
|
864
|
-
|
|
877
|
+
return pc[name](arg)
|
|
865
878
|
}
|
|
866
|
-
|
|
879
|
+
},
|
|
880
|
+
)*/
|
|
867
881
|
// Simulate keypress
|
|
868
882
|
await page.exposeFunction('keypressText', async (selector, text, delay = 20) => {
|
|
869
883
|
await page.type(selector, text, { delay });
|
|
@@ -962,7 +976,7 @@ webrtcperf.config.AUDIO_URL = "http${this.serverUseHttps ? 's' : ''}://localhost
|
|
|
962
976
|
if (this.showPageLog || saveFile) {
|
|
963
977
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
964
978
|
page.on('pageerror', async (error) => {
|
|
965
|
-
const text = `pageerror: ${error
|
|
979
|
+
const text = `pageerror: ${error?.message?.message || error?.message || error} - ${error?.message?.stack || error?.stack}`;
|
|
966
980
|
await this.onPageMessage(index, 'error', text, saveFile);
|
|
967
981
|
});
|
|
968
982
|
page.on('requestfailed', async (request) => {
|
|
@@ -1065,11 +1079,23 @@ webrtcperf.config.AUDIO_URL = "http${this.serverUseHttps ? 's' : ''}://localhost
|
|
|
1065
1079
|
pageCDPSession.on('Network.webSocketFrameReceived', event => {
|
|
1066
1080
|
resourcesStats.wsRecvBytes += event.response.payloadData.length;
|
|
1067
1081
|
});
|
|
1068
|
-
//
|
|
1082
|
+
// Hardware concurrency.
|
|
1069
1083
|
if (this.hardwareConcurrency) {
|
|
1070
1084
|
const plugin = NavigatorHardwareConcurrency({ hardwareConcurrency: this.hardwareConcurrency });
|
|
1071
1085
|
await plugin.onPageCreated(page);
|
|
1072
1086
|
}
|
|
1087
|
+
// Network throttling.
|
|
1088
|
+
if (this.throttleIndex > -1 && (process.platform !== 'linux' || this.useBrowserThrottling)) {
|
|
1089
|
+
log.debug(`Using internal network throttling`);
|
|
1090
|
+
await pageCDPSession.send('Network.emulateNetworkConditions', {
|
|
1091
|
+
offline: false,
|
|
1092
|
+
uploadThroughput: 100000000 / 8,
|
|
1093
|
+
downloadThroughput: 100000000 / 8,
|
|
1094
|
+
latency: 0,
|
|
1095
|
+
packetLoss: 0,
|
|
1096
|
+
packetQueueLength: 0,
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1073
1099
|
// Load page script.
|
|
1074
1100
|
{
|
|
1075
1101
|
const filePath = (0, utils_1.resolvePackagePath)('node_modules/@vpalmisano/webrtcperf-js/dist/webrtcperf.js');
|
|
@@ -1127,6 +1153,12 @@ webrtcperf.config.AUDIO_URL = "http${this.serverUseHttps ? 's' : ''}://localhost
|
|
|
1127
1153
|
}
|
|
1128
1154
|
// add to pages map
|
|
1129
1155
|
this.pages.set(index, page);
|
|
1156
|
+
if (this.throttleIndex > -1 && (process.platform !== 'linux' || this.useBrowserThrottling)) {
|
|
1157
|
+
await this.applyNetworkThrottling(pageCDPSession);
|
|
1158
|
+
throttler_1.throttleNotifier.on('change', async () => {
|
|
1159
|
+
await this.applyNetworkThrottling(pageCDPSession);
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1130
1162
|
log.debug(`Page ${index + 1} "${url}" loaded in ${(Date.now() - pageLoadTime) / 1000}s`);
|
|
1131
1163
|
for (let i = 0; i < this.evaluateAfter.length; i++) {
|
|
1132
1164
|
await page.evaluate(
|
|
@@ -1134,6 +1166,24 @@ webrtcperf.config.AUDIO_URL = "http${this.serverUseHttps ? 's' : ''}://localhost
|
|
|
1134
1166
|
this.evaluateAfter[i].pageFunction, ...this.evaluateAfter[i].args);
|
|
1135
1167
|
}
|
|
1136
1168
|
}
|
|
1169
|
+
async applyNetworkThrottling(pageCDPSession) {
|
|
1170
|
+
const throttleUpValues = (0, throttler_1.getSessionThrottleValues)(this.throttleIndex, 'up');
|
|
1171
|
+
const throttleDownValues = (0, throttler_1.getSessionThrottleValues)(this.throttleIndex, 'down');
|
|
1172
|
+
const params = {
|
|
1173
|
+
offline: false,
|
|
1174
|
+
uploadThroughput: throttleUpValues.rate || -1,
|
|
1175
|
+
downloadThroughput: throttleDownValues.rate || -1,
|
|
1176
|
+
latency: Math.max(throttleUpValues.delay || 0, throttleDownValues.delay || 0),
|
|
1177
|
+
packetLoss: Math.max(throttleUpValues.loss || 0, throttleDownValues.loss || 0),
|
|
1178
|
+
packetQueueLength: Math.max(throttleUpValues.queue || 0, throttleDownValues.queue || 0),
|
|
1179
|
+
};
|
|
1180
|
+
log.debug(`Apply internal network throttling: ${JSON.stringify(params)}`);
|
|
1181
|
+
await pageCDPSession.send('Network.emulateNetworkConditions', {
|
|
1182
|
+
...params,
|
|
1183
|
+
uploadThroughput: params.uploadThroughput !== -1 ? params.uploadThroughput / 8 : -1,
|
|
1184
|
+
downloadThroughput: params.downloadThroughput !== -1 ? params.downloadThroughput / 8 : -1,
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1137
1187
|
async getNewPage(tabIndex) {
|
|
1138
1188
|
log.debug(`getNewPage ${tabIndex}`);
|
|
1139
1189
|
(0, assert_1.default)(this.context, 'NoBrowserContextCreated');
|