async function runBundledLighthouse(url, config, testRunnerOptions) {
  if (isMainThread || !parentPort) {
    throw new Error('must be called in worker');
  }

  const originalBuffer = global.Buffer;
  const originalRequire = global.require;
  const originalProcess = global.process;
  if (typeof globalThis === 'undefined') {
    // @ts-expect-error - exposing for loading of dt-bundle.
    global.globalThis = global;
  }

  // Load bundle, which creates a `global.runBundledLighthouse`.
  await import(LH_ROOT + '/dist/lighthouse-dt-bundle.js');

  global.require = originalRequire;
  global.Buffer = originalBuffer;
  global.process = originalProcess;

  /** @type {import('../../../../core/index.js')['default']} */
  // @ts-expect-error - not worth giving test global an actual type.
  const lighthouse = global.runBundledLighthouse;

  /** @type {import('../../../../core/lib/third-party-web.js')['default']} */
  // @ts-expect-error
  const thirdPartyWeb = global.thirdPartyWeb;
  thirdPartyWeb.provideThirdPartyWeb(thirdPartyWebLib);

  // Launch and connect to Chrome.
  const launchedChrome = await ChromeLauncher.launch({
    chromeFlags: [
      testRunnerOptions?.headless ? '--headless=new' : '',
    ],
  });
  const port = launchedChrome.port;

  // Run Lighthouse.
  try {
    const logLevel = testRunnerOptions?.isDebug ? 'verbose' : 'info';

    // Puppeteer is not included in the bundle, we must create the page here.
    const browser = await puppeteer.connect({browserURL: `http://127.0.0.1:${port}`});
    const page = await browser.newPage();
    const runnerResult = await lighthouse(url, {port, logLevel}, config, page);
    if (!runnerResult) throw new Error('No runnerResult');

    return {
      lhr: runnerResult.lhr,
      artifacts: runnerResult.artifacts,
    };
  } finally {
    // Clean up and return results.
    launchedChrome.kill();
  }
}
@param {string} url
@param {LH.Config|undefined} config
@param {Smokehouse.SmokehouseOptions['testRunnerOptions']} testRunnerOptions
@return {Promise<{lhr: LH.Result, artifacts: LH.Artifacts}>}