Repository: puppeteer/puppeteer
File: packages/browsers/src/launch.ts (TypeScript)

Code before:
  // we will be invoked.
  #hooksRan = false;
  #onExitHook = async () => {};
  #browserProcessExiting: Promise<void>;
  #logs: string[] = [];
  #maxLogLinesSize = 1000;
  #lineEmitter = new EventEmitter();
  #onAbort: () => void = () => {
    this.kill();
  };
  #signal?: AbortSignal;

  constructor(opts: LaunchOptions) {
    this.#executablePath = opts.executablePath;
    this.#args = opts.args ?? [];

    if (opts.signal) {
      this.#signal = opts.signal;
      if (this.#signal.aborted) {
        throw new Error(
          this.#signal.reason ? this.#signal.reason : 'Launch aborted',
        );
      }
      this.#signal.addEventListener('abort', this.#onAbort, {once: true});
    }

    opts.pipe ??= false;
    opts.dumpio ??= false;
    opts.handleSIGINT ??= true;
    opts.handleSIGTERM ??= true;
    opts.handleSIGHUP ??= true;
    // On non-windows platforms, `detached: true` makes child process a
    // leader of a new process group, making it possible to kill child
    // process tree with `.kill(-pid)` command. @see
    // https://nodejs.org/api/child_process.html#child_process_options_detached
    opts.detached ??= process.platform !== 'win32';
    const stdio = this.#configureStdio({
      pipe: opts.pipe,
    });

    const env = opts.env || {};

    debugLaunch(`Launching ${this.#executablePath} ${this.#args.join(' ')}`, {
      detached: opts.detached,
      env: Object.keys(env).reduce<Record<string, string | undefined>>(
        (res, key) => {
          if (key.toLowerCase().startsWith('puppeteer_')) {
            res[key] = env[key];
          }
          return res;
        },

Review comment (suggestion):
```suggestion
      this.#signal = opts.signal;
      if (this.#signal?.aborted) {
        throw new Error(
          this.#signal.reason ? this.#signal.reason : 'Launch aborted',
        );
      }
      this.#signal?.addEventListener('abort', this.#onAbort, {once: true});

```

Code after:
  // we will be invoked.
  #hooksRan = false;
  #onExitHook = async () => {};
  #browserProcessExiting: Promise<void>;
  #logs: string[] = [];
  #maxLogLinesSize = 1000;
  #lineEmitter = new EventEmitter();
  #onAbort = (): void => {
    this.kill();
  };
  #signal?: AbortSignal;

  constructor(opts: LaunchOptions) {
    this.#executablePath = opts.executablePath;
    this.#args = opts.args ?? [];

    this.#signal = opts.signal;
    if (this.#signal?.aborted) {
      throw new Error(
        this.#signal.reason ? this.#signal.reason : 'Launch aborted',
      );
    }
    this.#signal?.addEventListener('abort', this.#onAbort, {once: true});

    opts.pipe ??= false;
    opts.dumpio ??= false;
    opts.handleSIGINT ??= true;
    opts.handleSIGTERM ??= true;
    opts.handleSIGHUP ??= true;
    // On non-windows platforms, `detached: true` makes child process a
    // leader of a new process group, making it possible to kill child
    // process tree with `.kill(-pid)` command. @see
    // https://nodejs.org/api/child_process.html#child_process_options_detached
    opts.detached ??= process.platform !== 'win32';
    const stdio = this.#configureStdio({
      pipe: opts.pipe,
    });

    const env = opts.env || {};

    debugLaunch(`Launching ${this.#executablePath} ${this.#args.join(' ')}`, {
      detached: opts.detached,
      env: Object.keys(env).reduce<Record<string, string | undefined>>(
        (res, key) => {
          if (key.toLowerCase().startsWith('puppeteer_')) {
            res[key] = env[key];
          }
          return res;
        },
        {},
      ),