diff --git a/docs/api/index.md b/docs/api/index.md
index 9eabae6bfd5..13251d4168b 100644
--- a/docs/api/index.md
+++ b/docs/api/index.md
@@ -120,18 +120,18 @@ sidebar_label: API
## Variables
-| Variable | Description |
-| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| [connect](./puppeteer.connect.md) | |
-| [createBrowserFetcher](./puppeteer.createbrowserfetcher.md) | |
-| [DEFAULT_INTERCEPT_RESOLUTION_PRIORITY](./puppeteer.default_intercept_resolution_priority.md) | The default cooperative request interception resolution priority |
-| [defaultArgs](./puppeteer.defaultargs.md) | |
-| [devices](./puppeteer.devices.md) | A list of devices to be used with page.emulate(options)
. Actual list of devices can be found in [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts). |
-| [errors](./puppeteer.errors.md) |
Puppeteer methods might throw errors if they are unable to fulfill a request. For example, page.waitForSelector(selector[, options])
might fail if the selector doesn't match any nodes during the given timeframe.
For certain types of errors Puppeteer uses specific error classes. These classes are available via puppeteer.errors
.
page.emulateNetworkConditions(networkConditions)
. Actual list of predefined conditions can be found in [src/common/NetworkConditions.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/NetworkConditions.ts). |
+| Variable | Description |
+| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [connect](./puppeteer.connect.md) | |
+| [createBrowserFetcher](./puppeteer.createbrowserfetcher.md) | |
+| [DEFAULT_INTERCEPT_RESOLUTION_PRIORITY](./puppeteer.default_intercept_resolution_priority.md) | The default cooperative request interception resolution priority |
+| [defaultArgs](./puppeteer.defaultargs.md) | |
+| [devices](./puppeteer.devices.md) | A list of devices to be used with page.emulate(options)
. Actual list of devices can be found in [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts). |
+| [errors](./puppeteer.errors.md) | |
+| [EVALUATION_SCRIPT_URL](./puppeteer.evaluation_script_url.md) | |
+| [executablePath](./puppeteer.executablepath.md) | |
+| [launch](./puppeteer.launch.md) | |
+| [networkConditions](./puppeteer.networkconditions.md) | A list of network conditions to be used with page.emulateNetworkConditions(networkConditions)
. Actual list of predefined conditions can be found in [src/common/NetworkConditions.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/NetworkConditions.ts). |
## Type Aliases
diff --git a/docs/api/puppeteer.customerror._constructor_.md b/docs/api/puppeteer.customerror._constructor_.md
deleted file mode 100644
index 6283b96d0b0..00000000000
--- a/docs/api/puppeteer.customerror._constructor_.md
+++ /dev/null
@@ -1,21 +0,0 @@
----
-sidebar_label: CustomError.(constructor)
----
-
-# CustomError.(constructor)
-
-Constructs a new instance of the `CustomError` class
-
-**Signature:**
-
-```typescript
-class CustomError {
- constructor(message?: string);
-}
-```
-
-## Parameters
-
-| Parameter | Type | Description |
-| --------- | ------ | ----------------- |
-| message | string | (Optional) |
diff --git a/docs/api/puppeteer.customerror.md b/docs/api/puppeteer.customerror.md
index fd30b1edf85..0fc5796e804 100644
--- a/docs/api/puppeteer.customerror.md
+++ b/docs/api/puppeteer.customerror.md
@@ -4,6 +4,10 @@ sidebar_label: CustomError
# CustomError class
+> Warning: This API is now obsolete.
+>
+> Do not use.
+
**Signature:**
```typescript
@@ -12,8 +16,6 @@ export declare class CustomError extends Error
**Extends:** Error
-## Constructors
+## Remarks
-| Constructor | Modifiers | Description |
-| ------------------------------------------------------------------ | --------- | --------------------------------------------------------------- |
-| [(constructor)(message)](./puppeteer.customerror._constructor_.md) | | Constructs a new instance of the CustomError
class |
+The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `CustomError` class.
diff --git a/docs/api/puppeteer.errors.md b/docs/api/puppeteer.errors.md
index 81ddf0545d7..eeb7d75bbe0 100644
--- a/docs/api/puppeteer.errors.md
+++ b/docs/api/puppeteer.errors.md
@@ -4,9 +4,13 @@ sidebar_label: errors
# errors variable
-Puppeteer methods might throw errors if they are unable to fulfill a request. For example, `page.waitForSelector(selector[, options])` might fail if the selector doesn't match any nodes during the given timeframe.
-
-For certain types of errors Puppeteer uses specific error classes. These classes are available via `puppeteer.errors`.
+> Warning: This API is now obsolete.
+>
+> Import error classes directly.
+>
+> Puppeteer methods might throw errors if they are unable to fulfill a request. For example, `page.waitForSelector(selector[, options])` might fail if the selector doesn't match any nodes during the given timeframe.
+>
+> For certain types of errors Puppeteer uses specific error classes. These classes are available via `puppeteer.errors`.
**Signature:**
@@ -22,7 +26,7 @@ An example of handling a timeout error:
try {
await page.waitForSelector('.foo');
} catch (e) {
- if (e instanceof puppeteer.errors.TimeoutError) {
+ if (e instanceof TimeoutError) {
// Do something if this is a timeout.
}
}
diff --git a/docs/api/puppeteer.protocolerror.code.md b/docs/api/puppeteer.protocolerror.code.md
index a6e01b172ec..20c09541e9a 100644
--- a/docs/api/puppeteer.protocolerror.code.md
+++ b/docs/api/puppeteer.protocolerror.code.md
@@ -8,6 +8,6 @@ sidebar_label: ProtocolError.code
```typescript
class ProtocolError {
- code?: number;
+ set code(code: number | undefined);
}
```
diff --git a/docs/api/puppeteer.protocolerror.md b/docs/api/puppeteer.protocolerror.md
index a9492d5306b..180e7f309fd 100644
--- a/docs/api/puppeteer.protocolerror.md
+++ b/docs/api/puppeteer.protocolerror.md
@@ -16,7 +16,7 @@ export declare class ProtocolError extends CustomError
## Properties
-| Property | Modifiers | Type | Description |
-| --------------------------------------------------------------- | --------- | ------ | ----------------- |
-| [code?](./puppeteer.protocolerror.code.md) | | number | (Optional) |
-| [originalMessage](./puppeteer.protocolerror.originalmessage.md) | | string | |
+| Property | Modifiers | Type | Description |
+| --------------------------------------------------------------- | --------- | ------------------- | ----------- |
+| [code](./puppeteer.protocolerror.code.md) | | number \| undefined | |
+| [originalMessage](./puppeteer.protocolerror.originalmessage.md) | | string | |
diff --git a/docs/api/puppeteer.protocolerror.originalmessage.md b/docs/api/puppeteer.protocolerror.originalmessage.md
index 5dd13b88cfa..440af0b2bf4 100644
--- a/docs/api/puppeteer.protocolerror.originalmessage.md
+++ b/docs/api/puppeteer.protocolerror.originalmessage.md
@@ -8,6 +8,6 @@ sidebar_label: ProtocolError.originalMessage
```typescript
class ProtocolError {
- originalMessage: string;
+ set originalMessage(originalMessage: string);
}
```
diff --git a/docs/api/puppeteer.puppeteer.errors.md b/docs/api/puppeteer.puppeteer.errors.md
deleted file mode 100644
index 3995d28d88a..00000000000
--- a/docs/api/puppeteer.puppeteer.errors.md
+++ /dev/null
@@ -1,23 +0,0 @@
----
-sidebar_label: Puppeteer.errors
----
-
-# Puppeteer.errors property
-
-> Warning: This API is now obsolete.
->
-> Import directly puppeteer.
-
-**Signature:**
-
-```typescript
-class Puppeteer {
- get errors(): typeof errors;
-}
-```
-
-## Example
-
-```ts
-import {errors} from 'puppeteer';
-```
diff --git a/docs/api/puppeteer.puppeteer.md b/docs/api/puppeteer.puppeteer.md
index 0968b799653..bfc92d795b9 100644
--- a/docs/api/puppeteer.puppeteer.md
+++ b/docs/api/puppeteer.puppeteer.md
@@ -23,7 +23,6 @@ The constructor for this class is marked as internal. Third-party code should no
| Property | Modifiers | Type | Description |
| --------------------------------------------------------------- | --------------------- | ------------------------------------------------------------ | ----------- |
| [devices](./puppeteer.puppeteer.devices.md) | readonly
| typeof [devices](./puppeteer.devices.md) | |
-| [errors](./puppeteer.puppeteer.errors.md) | readonly
| typeof [errors](./puppeteer.errors.md) | |
| [networkConditions](./puppeteer.puppeteer.networkconditions.md) | readonly
| typeof [networkConditions](./puppeteer.networkconditions.md) | |
## Methods
diff --git a/docs/api/puppeteer.puppeteererrors.md b/docs/api/puppeteer.puppeteererrors.md
index e0bdd7a1292..c52ef868fa9 100644
--- a/docs/api/puppeteer.puppeteererrors.md
+++ b/docs/api/puppeteer.puppeteererrors.md
@@ -4,6 +4,10 @@ sidebar_label: PuppeteerErrors
# PuppeteerErrors interface
+> Warning: This API is now obsolete.
+>
+> Do not use.
+
**Signature:**
```typescript
diff --git a/packages/puppeteer-core/src/common/Errors.ts b/packages/puppeteer-core/src/common/Errors.ts
index 56a6117b8f5..32f2ad6b97e 100644
--- a/packages/puppeteer-core/src/common/Errors.ts
+++ b/packages/puppeteer-core/src/common/Errors.ts
@@ -15,9 +15,14 @@
*/
/**
+ * @deprecated Do not use.
+ *
* @public
*/
export class CustomError extends Error {
+ /**
+ * @internal
+ */
constructor(message?: string) {
super(message);
this.name = this.constructor.name;
@@ -43,11 +48,39 @@ export class TimeoutError extends CustomError {}
* @public
*/
export class ProtocolError extends CustomError {
- public code?: number;
- public originalMessage = '';
+ #code?: number;
+ #originalMessage = '';
+
+ /**
+ * @internal
+ */
+ set code(code: number | undefined) {
+ this.#code = code;
+ }
+ /**
+ * @public
+ */
+ get code(): number | undefined {
+ return this.#code;
+ }
+
+ /**
+ * @internal
+ */
+ set originalMessage(originalMessage: string) {
+ this.#originalMessage = originalMessage;
+ }
+ /**
+ * @public
+ */
+ get originalMessage(): string {
+ return this.#originalMessage;
+ }
}
/**
+ * @deprecated Do not use.
+ *
* @public
*/
export interface PuppeteerErrors {
@@ -56,6 +89,8 @@ export interface PuppeteerErrors {
}
/**
+ * @deprecated Import error classes directly.
+ *
* Puppeteer methods might throw errors if they are unable to fulfill a request.
* For example, `page.waitForSelector(selector[, options])` might fail if the
* selector doesn't match any nodes during the given timeframe.
@@ -70,7 +105,7 @@ export interface PuppeteerErrors {
* try {
* await page.waitForSelector('.foo');
* } catch (e) {
- * if (e instanceof puppeteer.errors.TimeoutError) {
+ * if (e instanceof TimeoutError) {
* // Do something if this is a timeout.
* }
* }
diff --git a/packages/puppeteer-core/src/common/Puppeteer.ts b/packages/puppeteer-core/src/common/Puppeteer.ts
index 8fab36e1c5b..994b5eb322a 100644
--- a/packages/puppeteer-core/src/common/Puppeteer.ts
+++ b/packages/puppeteer-core/src/common/Puppeteer.ts
@@ -20,7 +20,6 @@ import {
} from './BrowserConnector.js';
import {ConnectionTransport} from './ConnectionTransport.js';
import {devices} from './DeviceDescriptors.js';
-import {errors} from './Errors.js';
import {networkConditions} from './NetworkConditions.js';
import {
clearCustomQueryHandlers,
@@ -99,18 +98,6 @@ export class Puppeteer {
return devices;
}
- /**
- * @deprecated Import directly puppeteer.
- * @example
- *
- * ```ts
- * import {errors} from 'puppeteer';
- * ```
- */
- get errors(): typeof errors {
- return errors;
- }
-
/**
* @deprecated Import directly puppeteer.
* @example
diff --git a/test/src/ariaqueryhandler.spec.ts b/test/src/ariaqueryhandler.spec.ts
index 6df4f1fe483..1dc4421b1b9 100644
--- a/test/src/ariaqueryhandler.spec.ts
+++ b/test/src/ariaqueryhandler.spec.ts
@@ -24,6 +24,7 @@ import {
import {ElementHandle} from 'puppeteer-core/internal/common/ElementHandle.js';
import utils from './utils.js';
import assert from 'assert';
+import {TimeoutError} from 'puppeteer';
describe('AriaQueryHandler', () => {
setupTestBrowserHooks();
@@ -516,7 +517,7 @@ describe('AriaQueryHandler', () => {
});
it('should respect timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
const error = await page
.waitForSelector('aria/[role="button"]', {
@@ -528,7 +529,7 @@ describe('AriaQueryHandler', () => {
expect(error.message).toContain(
'Waiting for selector `[role="button"]` failed: Waiting failed: 10ms exceeded'
);
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should have an error message specifically for awaiting an element to be hidden', async () => {
diff --git a/test/src/browsercontext.spec.ts b/test/src/browsercontext.spec.ts
index 09eb0e4e709..45e2ddc86f0 100644
--- a/test/src/browsercontext.spec.ts
+++ b/test/src/browsercontext.spec.ts
@@ -15,6 +15,7 @@
*/
import expect from 'expect';
+import {TimeoutError} from 'puppeteer';
import {getTestState, setupTestBrowserHooks} from './mocha-utils.js';
import {waitEvent} from './utils.js';
@@ -96,7 +97,7 @@ describe('BrowserContext', function () {
await context.close();
});
it('should wait for a target', async () => {
- const {browser, puppeteer, server} = getTestState();
+ const {browser, server} = getTestState();
const context = await browser.createIncognitoBrowserContext();
let resolved = false;
@@ -110,7 +111,7 @@ describe('BrowserContext', function () {
})
.catch(error => {
resolved = true;
- if (error instanceof puppeteer.errors.TimeoutError) {
+ if (error instanceof TimeoutError) {
console.error(error);
} else {
throw error;
@@ -123,7 +124,7 @@ describe('BrowserContext', function () {
const target = await targetPromise;
expect(await target.page()).toBe(page);
} catch (error) {
- if (error instanceof puppeteer.errors.TimeoutError) {
+ if (error instanceof TimeoutError) {
console.error(error);
} else {
throw error;
@@ -133,7 +134,7 @@ describe('BrowserContext', function () {
});
it('should timeout waiting for a non-existent target', async () => {
- const {browser, puppeteer, server} = getTestState();
+ const {browser, server} = getTestState();
const context = await browser.createIncognitoBrowserContext();
const error = await context
@@ -148,7 +149,7 @@ describe('BrowserContext', function () {
.catch(error_ => {
return error_;
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
await context.close();
});
diff --git a/test/src/input.spec.ts b/test/src/input.spec.ts
index 925125a2c74..a681717402e 100644
--- a/test/src/input.spec.ts
+++ b/test/src/input.spec.ts
@@ -21,6 +21,7 @@ import {
setupTestBrowserHooks,
setupTestPageAndContextHooks,
} from './mocha-utils.js';
+import {TimeoutError} from 'puppeteer';
const FILE_TO_UPLOAD = path.join(__dirname, '/../assets/file-to-upload.txt');
@@ -100,33 +101,33 @@ describe('input tests', function () {
expect(chooser).toBeTruthy();
});
it('should respect timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
await page.waitForFileChooser({timeout: 1}).catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should respect default timeout when there is no custom timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
page.setDefaultTimeout(1);
let error!: Error;
await page.waitForFileChooser().catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should prioritize exact timeout over default timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
page.setDefaultTimeout(0);
let error!: Error;
await page.waitForFileChooser({timeout: 1}).catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should work with no timeout', async () => {
const {page} = getTestState();
diff --git a/test/src/launcher.spec.ts b/test/src/launcher.spec.ts
index 718a4718794..1b261f21f30 100644
--- a/test/src/launcher.spec.ts
+++ b/test/src/launcher.spec.ts
@@ -26,6 +26,7 @@ import {Page} from 'puppeteer-core/internal/api/Page.js';
import {Product} from 'puppeteer-core/internal/common/Product.js';
import {getTestState, itOnlyRegularInstall} from './mocha-utils.js';
import utils from './utils.js';
+import {TimeoutError} from 'puppeteer';
const mkdtempAsync = promisify(fs.mkdtemp);
const readFileAsync = promisify(fs.readFile);
@@ -529,7 +530,7 @@ describe('Launcher specs', function () {
await puppeteer.launch(options).catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should work with timeout = 0', async () => {
const {puppeteer, defaultBrowserOptions} = getTestState();
diff --git a/test/src/navigation.spec.ts b/test/src/navigation.spec.ts
index 4e3792f7730..61e3fc0ac35 100644
--- a/test/src/navigation.spec.ts
+++ b/test/src/navigation.spec.ts
@@ -24,6 +24,7 @@ import {
import os from 'os';
import {ServerResponse} from 'http';
import {HTTPRequest} from 'puppeteer-core/internal/common/HTTPRequest.js';
+import {TimeoutError} from 'puppeteer';
describe('navigation', function () {
setupTestBrowserHooks();
@@ -228,7 +229,7 @@ describe('navigation', function () {
}
});
it('should fail when exceeding maximum navigation timeout', async () => {
- const {page, server, puppeteer} = getTestState();
+ const {page, server} = getTestState();
// Hang for request to the empty.html
server.setRoute('/empty.html', () => {});
@@ -239,10 +240,10 @@ describe('navigation', function () {
return (error = error_);
});
expect(error.message).toContain('Navigation timeout of 1 ms exceeded');
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should fail when exceeding default maximum navigation timeout', async () => {
- const {page, server, puppeteer} = getTestState();
+ const {page, server} = getTestState();
// Hang for request to the empty.html
server.setRoute('/empty.html', () => {});
@@ -252,10 +253,10 @@ describe('navigation', function () {
return (error = error_);
});
expect(error.message).toContain('Navigation timeout of 1 ms exceeded');
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should fail when exceeding default maximum timeout', async () => {
- const {page, server, puppeteer} = getTestState();
+ const {page, server} = getTestState();
// Hang for request to the empty.html
server.setRoute('/empty.html', () => {});
@@ -265,10 +266,10 @@ describe('navigation', function () {
return (error = error_);
});
expect(error.message).toContain('Navigation timeout of 1 ms exceeded');
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should prioritize default navigation timeout over default timeout', async () => {
- const {page, server, puppeteer} = getTestState();
+ const {page, server} = getTestState();
// Hang for request to the empty.html
server.setRoute('/empty.html', () => {});
@@ -279,7 +280,7 @@ describe('navigation', function () {
return (error = error_);
});
expect(error.message).toContain('Navigation timeout of 1 ms exceeded');
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should disable timeout when its set to 0', async () => {
const {page, server} = getTestState();
diff --git a/test/src/page.spec.ts b/test/src/page.spec.ts
index b490b1af12b..0264a5bbe0a 100644
--- a/test/src/page.spec.ts
+++ b/test/src/page.spec.ts
@@ -28,6 +28,7 @@ import {
} from './mocha-utils.js';
import utils, {attachFrame, waitEvent} from './utils.js';
import {CDPPage} from 'puppeteer-core/internal/common/Page.js';
+import {TimeoutError} from 'puppeteer';
describe('Page', function () {
setupTestBrowserHooks();
@@ -924,7 +925,7 @@ describe('Page', function () {
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
});
it('should respect timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
await page
@@ -937,10 +938,10 @@ describe('Page', function () {
.catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should respect default timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
page.setDefaultTimeout(1);
@@ -951,7 +952,7 @@ describe('Page', function () {
.catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should work with no timeout', async () => {
const {page, server} = getTestState();
@@ -987,7 +988,7 @@ describe('Page', function () {
expect(response.url()).toBe(server.PREFIX + '/digits/2.png');
});
it('should respect timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
await page
@@ -1000,10 +1001,10 @@ describe('Page', function () {
.catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should respect default timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
page.setDefaultTimeout(1);
@@ -1014,7 +1015,7 @@ describe('Page', function () {
.catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should work with predicate', async () => {
const {page, server} = getTestState();
@@ -1101,12 +1102,12 @@ describe('Page', function () {
expect(t1 - t2).toBeGreaterThanOrEqual(400);
});
it('should respect timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
await page.waitForNetworkIdle({timeout: 1}).catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should respect idleTime', async () => {
const {page, server} = getTestState();
@@ -1440,7 +1441,7 @@ describe('Page', function () {
expect(result).toBe(`${doctype}${expectedOutput}`);
});
it('should respect timeout', async () => {
- const {page, server, puppeteer} = getTestState();
+ const {page, server} = getTestState();
const imgPath = '/img.png';
// stall for image
@@ -1453,10 +1454,10 @@ describe('Page', function () {
.catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should respect default navigation timeout', async () => {
- const {page, server, puppeteer} = getTestState();
+ const {page, server} = getTestState();
page.setDefaultNavigationTimeout(1);
const imgPath = '/img.png';
@@ -1468,7 +1469,7 @@ describe('Page', function () {
.catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
it('should await resources to load', async () => {
const {page, server} = getTestState();
@@ -2053,7 +2054,7 @@ describe('Page', function () {
});
it('should respect timeout', async () => {
- const {isHeadless, page, server, puppeteer} = getTestState();
+ const {isHeadless, page, server} = getTestState();
if (!isHeadless) {
return;
}
@@ -2064,7 +2065,7 @@ describe('Page', function () {
await page.pdf({timeout: 1}).catch(_error => {
return (error = _error);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
});
diff --git a/test/src/target.spec.ts b/test/src/target.spec.ts
index db2ca108479..f031d2d347c 100644
--- a/test/src/target.spec.ts
+++ b/test/src/target.spec.ts
@@ -16,6 +16,7 @@
import expect from 'expect';
import {ServerResponse} from 'http';
+import {TimeoutError} from 'puppeteer';
import {Page} from 'puppeteer-core/internal/api/Page.js';
import {Target} from 'puppeteer-core/internal/common/Target.js';
import {
@@ -310,7 +311,7 @@ describe('Target', function () {
describe('Browser.waitForTarget', () => {
it('should wait for a target', async () => {
- const {browser, puppeteer, server} = getTestState();
+ const {browser, server} = getTestState();
let resolved = false;
const targetPromise = browser.waitForTarget(target => {
@@ -322,7 +323,7 @@ describe('Target', function () {
})
.catch(error => {
resolved = true;
- if (error instanceof puppeteer.errors.TimeoutError) {
+ if (error instanceof TimeoutError) {
console.error(error);
} else {
throw error;
@@ -335,7 +336,7 @@ describe('Target', function () {
const target = await targetPromise;
expect(await target.page()).toBe(page);
} catch (error) {
- if (error instanceof puppeteer.errors.TimeoutError) {
+ if (error instanceof TimeoutError) {
console.error(error);
} else {
throw error;
@@ -344,7 +345,7 @@ describe('Target', function () {
await page.close();
});
it('should timeout waiting for a non-existent target', async () => {
- const {browser, server, puppeteer} = getTestState();
+ const {browser, server} = getTestState();
let error!: Error;
await browser
@@ -359,7 +360,7 @@ describe('Target', function () {
.catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
});
});
});
diff --git a/test/src/waittask.spec.ts b/test/src/waittask.spec.ts
index 468673e0f77..36941ff81b8 100644
--- a/test/src/waittask.spec.ts
+++ b/test/src/waittask.spec.ts
@@ -15,6 +15,7 @@
*/
import expect from 'expect';
+import {TimeoutError} from 'puppeteer';
import {isErrorLike} from 'puppeteer-core/internal/util/ErrorLike.js';
import {
createTimeout,
@@ -240,7 +241,7 @@ describe('waittask specs', function () {
await waitForFunction;
});
it('should respect timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
await page
@@ -254,11 +255,11 @@ describe('waittask specs', function () {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
expect(error?.message).toContain('Waiting failed: 10ms exceeded');
});
it('should respect default timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
page.setDefaultTimeout(1);
let error!: Error;
@@ -269,7 +270,7 @@ describe('waittask specs', function () {
.catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
expect(error?.message).toContain('Waiting failed: 1ms exceeded');
});
it('should disable timeout when its set to 0', async () => {
@@ -669,13 +670,13 @@ describe('waittask specs', function () {
expect(handle).toBe(null);
});
it('should respect timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
await page.waitForSelector('div', {timeout: 10}).catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
expect(error?.message).toContain(
'Waiting for selector `div` failed: Waiting failed: 10ms exceeded'
);
@@ -755,13 +756,13 @@ describe('waittask specs', function () {
).toBe('hello world ');
});
it('should respect timeout', async () => {
- const {page, puppeteer} = getTestState();
+ const {page} = getTestState();
let error!: Error;
await page.waitForXPath('//div', {timeout: 10}).catch(error_ => {
return (error = error_);
});
- expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
+ expect(error).toBeInstanceOf(TimeoutError);
expect(error?.message).toContain('Waiting failed: 10ms exceeded');
});
it('should run in specified frame', async () => {