berstend / puppeteer-extra

💯 Teach puppeteer new tricks through plugins.
https://extra.community
MIT License
6.23k stars 731 forks source link

missing error imports #871

Open SayWut opened 5 months ago

SayWut commented 5 months ago

Describe the bug

My node project is an esm typescript module. I am trying to catch a timeout error on the page but I unable to find the import of TimeoutError object from puppeteer-extra. I tried to import if from the puppeteer and puppeteer-core packages but it doesn't recognized as the same object.

Code Snippet

try {
    req = await page.waitForRequest((req) => {
        const checkUrl = /test/g.test(req.url());
        const checkRequestMethod = req.method() === "POST";

        return checkUrl && checkRequestMethod;
    }, {
        timeout: 3000
    });
}
catch (err) {
    if (err instanceof TimeoutError) {
        throw new Error("Some required input fields aren't supported");
    }
}

This is the type of imports that I tried so far but nothing worked:

import { TimeoutError } from "puppeteer-core/lib/esm/puppeteer/common/Errors.js";
import { TimeoutError } from "puppeteer";
import { TimeoutError } from "puppeteer-core";

This is my current work around in the catch

//@ts-ignore
if (err.constructor.name === "TimeoutError") {
    throw new Error("Some required input fields aren't supported");
}

Versions

  System:
    OS: Windows 10 10.0.19045
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 3.32 GB / 15.94 GB
  Binaries:
    Node: 19.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.6.3 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    puppeteer: ^21.0.3 => 21.0.3
    puppeteer-extra: ^3.3.6 => 3.3.6
    puppeteer-extra-plugin-adblocker: ^2.13.6 => 2.13.6
    puppeteer-extra-plugin-stealth: ^2.11.2 => 2.11.2