Repository: puppeteer/puppeteer
File: packages/puppeteer-core/src/common/WaitTask.ts (TypeScript)

Code before:
      // When frame is detached the task should have been terminated by the IsolatedWorld.
      // This can fail if we were adding this task while the frame was detached,
      // so we terminate here instead.
      if (
        error.message.includes(
          'Execution context is not available in detached frame'
        )
      ) {
        return new Error('Waiting failed: Frame detached');
      }

      // When the page is navigated, the promise is rejected.
      // We will try again in the new execution context.
      if (error.message.includes('Execution context was destroyed')) {
        return;
      }

      // We could have tried to evaluate in a context which was already
      // destroyed.
      if (error.message.includes('Cannot find context with specified id')) {
        return;
      }

      // Errors coming from WebDriver BiDi. TODO: Adjust messages after
      // https://github.com/w3c/webdriver-bidi/issues/540 is resolved.
      if (error.message.includes("Actor 'MessageHandlerFrame' destroyed")) {
        return;
      }

      return error;
    }

    return new Error('WaitTask failed with an error', {
      cause: error,
    });
  }
}

/**
 * @internal
 */
export class TaskManager {
  #tasks: Set<WaitTask> = new Set<WaitTask>();

  add(task: WaitTask<any>): void {
    this.#tasks.add(task);
  }

  delete(task: WaitTask<any>): void {
    this.#tasks.delete(task);
  }

Review comment (suggestion):
I would include the `AbortError: ` part here to really only let it apply for IPC issues when trying to send the response in Firefox.

Code after:
        // Ignore errors since they most likely come from low-level cleanup.
      }
    }
  }

  /**
   * Not all errors lead to termination. They usually imply we need to rerun the task.
   */
  getBadError(error: unknown): Error | undefined {
    if (isErrorLike(error)) {
      // When frame is detached the task should have been terminated by the IsolatedWorld.
      // This can fail if we were adding this task while the frame was detached,
      // so we terminate here instead.
      if (
        error.message.includes(
          'Execution context is not available in detached frame'
        )
      ) {
        return new Error('Waiting failed: Frame detached');
      }

      // When the page is navigated, the promise is rejected.
      // We will try again in the new execution context.
      if (error.message.includes('Execution context was destroyed')) {
        return;
      }

      // We could have tried to evaluate in a context which was already
      // destroyed.
      if (error.message.includes('Cannot find context with specified id')) {
        return;
      }

      // Errors coming from WebDriver BiDi. TODO: Adjust messages after
      // https://github.com/w3c/webdriver-bidi/issues/540 is resolved.
      if (
        error.message.includes(
          "AbortError: Actor 'MessageHandlerFrame' destroyed"
        )
      ) {
        return;
      }

      return error;
    }

    return new Error('WaitTask failed with an error', {
      cause: error,
    });
  }
}