async function stopServiceWorker(driver, extensionId) {
  const host = `chrome-extension://${extensionId}`;

  // Find the extension service worker
  const response = await cdpConnection.send('Target.getTargets', {});
  const worker = response.result.targetInfos.find(
    (t) => t.type === 'service_worker' && t.url.startsWith(host)
  );

  if (!worker) {
    throw new Error(`No worker found for ${host}`);
  }

  // Terminate the service worker
  await cdpConnection.send('Target.closeTarget', {
    targetId: worker.targetId
  });
}
Stops the service worker associated with a given extension ID. This is done
by creating a new Chrome DevTools Protocol session, finding the target ID
associated with the worker and running the Target.closeTarget command.

@param {Driver} driver Driver that CDP session can be started from
@param {string} extensionId Extension ID of worker to terminate