Skip to content

Commit 3d49eb4

Browse files
author
Eryk Kolodziej
committed
feat(core): add config to skip waiting for browser close
1 parent da1e05c commit 3d49eb4

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

packages/core/src/lib/Config.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @oncall web_perf_infra
99
*/
1010

11-
import type {Permission} from 'puppeteer';
11+
import type { Permission } from 'puppeteer';
1212
import type {
1313
AnyFunction,
1414
FileOption,
@@ -28,8 +28,8 @@ import path from 'path';
2828
import modes from '../modes/RunningModes';
2929
import info from './Console';
3030
import constant from './Constant';
31-
import fileManager, {FileManager} from './FileManager';
32-
import {setInternalValue} from './InternalValueSetter';
31+
import fileManager, { FileManager } from './FileManager';
32+
import { setInternalValue } from './InternalValueSetter';
3333

3434
interface Device {
3535
name: string;
@@ -240,6 +240,7 @@ export class MemLabConfig {
240240
noReCluster: boolean;
241241
maxSamplesForClustering: number;
242242
filterTraceByName: Nullable<string>;
243+
skipBrowserCloseWait: boolean;
243244

244245
constructor(options: ConfigOption = {}) {
245246
// init properties, they can be configured manually
@@ -370,6 +371,8 @@ export class MemLabConfig {
370371
// if specified via CLI options, this will filter leak traces by
371372
// node and edge names in the leak trace
372373
this.filterTraceByName = null;
374+
// if true, memlab will not wait for the browser to close successfully
375+
this.skipBrowserCloseWait = false;
373376
}
374377

375378
// initialize configurable parameters
@@ -554,7 +557,7 @@ export class MemLabConfig {
554557
// eslint-disable-next-line @typescript-eslint/no-unused-vars
555558
_app: string,
556559
// eslint-disable-next-line @typescript-eslint/no-unused-vars
557-
_interaction: string,
560+
_interaction: string
558561
): string[] {
559562
return [];
560563
}
@@ -576,14 +579,14 @@ export class MemLabConfig {
576579

577580
public static resetConfigWithTransientDir(): MemLabConfig {
578581
const config = MemLabConfig.getInstance();
579-
fileManager.initDirs(config, {transient: true});
582+
fileManager.initDirs(config, { transient: true });
580583
return config;
581584
}
582585

583586
private haltOrThrow(
584587
msg: string,
585588
// eslint-disable-next-line @typescript-eslint/no-empty-function
586-
secondaryPrintCallback: AnyFunction = () => {},
589+
secondaryPrintCallback: AnyFunction = () => {}
587590
): void {
588591
if (this.errorHandling === ErrorHandling.Halt) {
589592
info.error(msg);
@@ -608,7 +611,7 @@ export class MemLabConfig {
608611
const externalFilter: ILeakFilter = {};
609612

610613
// set leak filter
611-
const {leakFilter, beforeLeakFilter, retainerReferenceFilter} = scenario;
614+
const { leakFilter, beforeLeakFilter, retainerReferenceFilter } = scenario;
612615
if (typeof leakFilter === 'function') {
613616
hasCallback = true;
614617
externalFilter.leakFilter = leakFilter;
@@ -647,8 +650,8 @@ export class MemLabConfig {
647650
this.haltOrThrow(
648651
`Invalid browser: ${v} ` +
649652
`(supported browsers: ${Object.keys(constant.supportedBrowsers).join(
650-
', ',
651-
)})`,
653+
', '
654+
)})`
652655
);
653656
}
654657
this._browser = constant.supportedBrowsers[v];
@@ -730,7 +733,7 @@ export class MemLabConfig {
730733

731734
setDevice(
732735
deviceName: string,
733-
options: {manualOverride?: boolean} = {},
736+
options: { manualOverride?: boolean } = {}
734737
): void {
735738
if (!options.manualOverride && this._deviceManualOverridden) {
736739
return;
@@ -747,8 +750,8 @@ export class MemLabConfig {
747750
const name = deviceName.split('-').join(' ');
748751
if (!devices[name]) {
749752
const supportedDevices = Array.from(Object.keys(devices))
750-
.filter(name => isNaN(parseInt(name, 10)))
751-
.map(name => name.split(' ').join('-'));
753+
.filter((name) => isNaN(parseInt(name, 10)))
754+
.map((name) => name.split(' ').join('-'));
752755
this.haltOrThrow(`Invalid device: ${name}`, () => {
753756
info.lowLevel(`(supported devies: ${supportedDevices.join(', ')})`);
754757
});

packages/core/src/lib/Utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,8 @@ async function closePuppeteer(
13251325
if (config.isLocalPuppeteer && !options.warmup) {
13261326
await Promise.all(pages.map(page => page.close()));
13271327
await browser.disconnect();
1328+
} else if (config.skipBrowserCloseWait === true) {
1329+
browser.close();
13281330
} else {
13291331
await browser.close();
13301332
}

0 commit comments

Comments
 (0)