graceful-playwright 1.1.9 → 1.3.0
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 +1 -0
- package/core.d.ts +2 -0
- package/core.js +25 -0
- package/package.json +2 -2
package/README.md
CHANGED
package/core.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export declare class GracefulPage {
|
|
|
40
40
|
autoRetryWhenFailed<T>(f: () => T | Promise<T>): Promise<T>;
|
|
41
41
|
/** @description proxy method to (await this.getPage()).evaluate */
|
|
42
42
|
evaluate: Page['evaluate'];
|
|
43
|
+
/** @description proxy method to (await this.getPage()).waitForSelector */
|
|
44
|
+
waitForSelector: Page['waitForSelector'];
|
|
43
45
|
/** @description proxy method to (await this.getPage()).fill */
|
|
44
46
|
fill: Page['fill'];
|
|
45
47
|
/** @description proxy method to (await this.getPage()).click */
|
package/core.js
CHANGED
|
@@ -49,6 +49,26 @@ class GracefulPage {
|
|
|
49
49
|
waitUntil: 'domcontentloaded',
|
|
50
50
|
...options,
|
|
51
51
|
});
|
|
52
|
+
if (response && response.status() === 429) {
|
|
53
|
+
let retryAfter = await response.headerValue('Retry-After');
|
|
54
|
+
if (retryAfter && +retryAfter) {
|
|
55
|
+
// e.g. 120 (seconds)
|
|
56
|
+
await sleep(+retryAfter * 1000);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
else if (retryAfter && new Date(retryAfter).getTime()) {
|
|
60
|
+
// e.g. "Wed, 21 Oct 2015 07:28:00 GMT"
|
|
61
|
+
let target = new Date(retryAfter).getTime();
|
|
62
|
+
let now = Date.now();
|
|
63
|
+
let diff = target - now;
|
|
64
|
+
await sleep(diff);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
let statusText = response.statusText() || 'Too Many Requests';
|
|
69
|
+
throw new Error(statusText);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
52
72
|
return response;
|
|
53
73
|
}
|
|
54
74
|
catch (error) {
|
|
@@ -99,6 +119,11 @@ class GracefulPage {
|
|
|
99
119
|
let page = await this.getPage();
|
|
100
120
|
return await page.evaluate(pageFunction, arg);
|
|
101
121
|
};
|
|
122
|
+
/** @description proxy method to (await this.getPage()).waitForSelector */
|
|
123
|
+
waitForSelector = async (selector, options) => {
|
|
124
|
+
let page = await this.getPage();
|
|
125
|
+
return await page.waitForSelector(selector, options);
|
|
126
|
+
};
|
|
102
127
|
/** @description proxy method to (await this.getPage()).fill */
|
|
103
128
|
fill = async (selector, value, options) => {
|
|
104
129
|
let page = await this.getPage();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graceful-playwright",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Gracefully handle timeout and network error with auto retry.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graceful",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"express": "^4.18.2",
|
|
61
61
|
"mocha": "^10.3.0",
|
|
62
62
|
"npm-run-all": "^4.1.5",
|
|
63
|
-
"playwright": "^1.
|
|
63
|
+
"playwright": "^1.50.0",
|
|
64
64
|
"rimraf": "^5.0.5",
|
|
65
65
|
"sinon": "^17.0.1",
|
|
66
66
|
"ts-mocha": "^10.0.0",
|