graceful-playwright 1.4.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/core.d.ts +13 -1
- package/core.js +15 -3
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -52,6 +52,8 @@ await browser.close()
|
|
|
52
52
|
|
|
53
53
|
## Typescript Signature
|
|
54
54
|
|
|
55
|
+
Main Class: `GracefulPage`
|
|
56
|
+
|
|
55
57
|
```typescript
|
|
56
58
|
import { Browser, BrowserContext, Page, Response } from 'playwright'
|
|
57
59
|
|
|
@@ -80,7 +82,10 @@ export class GracefulPage {
|
|
|
80
82
|
/** @description optimized version of page.close() */
|
|
81
83
|
close: Page['close']
|
|
82
84
|
|
|
83
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* @description graceful version of page.goto()
|
|
87
|
+
* @throws GotoError with response details when got 429 Too Many Requests without retry-after header
|
|
88
|
+
*/
|
|
84
89
|
goto(
|
|
85
90
|
url: string,
|
|
86
91
|
/**
|
|
@@ -103,6 +108,20 @@ export class GracefulPage {
|
|
|
103
108
|
}
|
|
104
109
|
```
|
|
105
110
|
|
|
111
|
+
Error Class: `GotoError`
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
export class GotoError extends Error {
|
|
115
|
+
constructor(message: string, public details: GotoErrorDetails)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type GotoErrorDetails = {
|
|
119
|
+
url: string
|
|
120
|
+
options?: Parameters<Page['goto']>[1]
|
|
121
|
+
response: Awaited<ReturnType<Page['goto']>>
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
106
125
|
## License
|
|
107
126
|
|
|
108
127
|
This project is licensed with [BSD-2-Clause](./LICENSE)
|
package/core.d.ts
CHANGED
|
@@ -31,7 +31,10 @@ export declare class GracefulPage {
|
|
|
31
31
|
restart(options?: Parameters<Page['close']>[0]): Promise<Page>;
|
|
32
32
|
/** @description optimized version of page.close() */
|
|
33
33
|
close: Page['close'];
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* @description graceful version of page.goto()
|
|
36
|
+
* @throws GotoError with response details when got 429 Too Many Requests without retry-after header
|
|
37
|
+
*/
|
|
35
38
|
goto(url: string,
|
|
36
39
|
/**
|
|
37
40
|
* @default { waitUtil: "domcontentloaded" }
|
|
@@ -55,4 +58,13 @@ export declare class GracefulPage {
|
|
|
55
58
|
/** @description proxy method to (await this.getPage()).innerText */
|
|
56
59
|
innerText: Page['innerText'];
|
|
57
60
|
}
|
|
61
|
+
export type GotoErrorDetails = {
|
|
62
|
+
url: string;
|
|
63
|
+
options?: Parameters<Page['goto']>[1];
|
|
64
|
+
response: Awaited<ReturnType<Page['goto']>>;
|
|
65
|
+
};
|
|
66
|
+
export declare class GotoError extends Error {
|
|
67
|
+
details: GotoErrorDetails;
|
|
68
|
+
constructor(message: string, details: GotoErrorDetails);
|
|
69
|
+
}
|
|
58
70
|
export declare function parseRetryAfter(headerValue: string | null): number | null;
|
package/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GracefulPage = void 0;
|
|
3
|
+
exports.GotoError = exports.GracefulPage = void 0;
|
|
4
4
|
exports.parseRetryAfter = parseRetryAfter;
|
|
5
5
|
class GracefulPage {
|
|
6
6
|
options;
|
|
@@ -37,7 +37,10 @@ class GracefulPage {
|
|
|
37
37
|
this.options.page = undefined;
|
|
38
38
|
return promise;
|
|
39
39
|
};
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* @description graceful version of page.goto()
|
|
42
|
+
* @throws GotoError with response details when got 429 Too Many Requests without retry-after header
|
|
43
|
+
*/
|
|
41
44
|
async goto(url,
|
|
42
45
|
/**
|
|
43
46
|
* @default { waitUtil: "domcontentloaded" }
|
|
@@ -58,7 +61,7 @@ class GracefulPage {
|
|
|
58
61
|
continue;
|
|
59
62
|
}
|
|
60
63
|
let statusText = response.statusText() || 'Too Many Requests';
|
|
61
|
-
throw new
|
|
64
|
+
throw new GotoError(statusText, { url, options, response });
|
|
62
65
|
}
|
|
63
66
|
return response;
|
|
64
67
|
}
|
|
@@ -68,6 +71,7 @@ class GracefulPage {
|
|
|
68
71
|
let isKnownError = message.includes(`Navigation to ${urlStr} is interrupted by another navigation to ${urlStr}`) ||
|
|
69
72
|
// e.g. 'Timeout 30000ms exceeded'
|
|
70
73
|
/Timeout [\w]+ exceeded/.test(message) ||
|
|
74
|
+
message.includes('ERR_INTERNET_DISCONNECTED') ||
|
|
71
75
|
message.includes('ERR_NETWORK_CHANGED') ||
|
|
72
76
|
message.includes('ERR_CONNECTION_RESET') ||
|
|
73
77
|
message.includes('ERR_SOCKET_NOT_CONNECTED') ||
|
|
@@ -147,6 +151,14 @@ class GracefulPage {
|
|
|
147
151
|
};
|
|
148
152
|
}
|
|
149
153
|
exports.GracefulPage = GracefulPage;
|
|
154
|
+
class GotoError extends Error {
|
|
155
|
+
details;
|
|
156
|
+
constructor(message, details) {
|
|
157
|
+
super(message);
|
|
158
|
+
this.details = details;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.GotoError = GotoError;
|
|
150
162
|
function sleep(ms) {
|
|
151
163
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
152
164
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graceful-playwright",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Gracefully handle timeout and network error with auto retry.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graceful",
|
|
@@ -58,14 +58,13 @@
|
|
|
58
58
|
"@types/sinon": "^17.0.1",
|
|
59
59
|
"chai": "4",
|
|
60
60
|
"express": "^4.18.2",
|
|
61
|
-
"mocha": "^
|
|
61
|
+
"mocha": "^11.2.2",
|
|
62
62
|
"npm-run-all": "^4.1.5",
|
|
63
|
-
"playwright": "^1.
|
|
64
|
-
"rimraf": "^
|
|
65
|
-
"sinon": "^
|
|
66
|
-
"ts-mocha": "^
|
|
63
|
+
"playwright": "^1.52.0",
|
|
64
|
+
"rimraf": "^6.0.1",
|
|
65
|
+
"sinon": "^20.0.0",
|
|
66
|
+
"ts-mocha": "^11.1.0",
|
|
67
67
|
"ts-node": "^10.9.2",
|
|
68
|
-
"ts-node-dev": "^2.0.0",
|
|
69
68
|
"typescript": "^5.3.3"
|
|
70
69
|
}
|
|
71
70
|
}
|