graceful-playwright 1.4.0 → 1.5.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.
Files changed (4) hide show
  1. package/README.md +20 -1
  2. package/core.d.ts +13 -1
  3. package/core.js +14 -3
  4. 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
- /** @description graceful version of page.goto() */
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
- /** @description graceful version of page.goto() */
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
- /** @description graceful version of page.goto() */
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 Error(statusText);
64
+ throw new GotoError(statusText, { url, options, response });
62
65
  }
63
66
  return response;
64
67
  }
@@ -147,6 +150,14 @@ class GracefulPage {
147
150
  };
148
151
  }
149
152
  exports.GracefulPage = GracefulPage;
153
+ class GotoError extends Error {
154
+ details;
155
+ constructor(message, details) {
156
+ super(message);
157
+ this.details = details;
158
+ }
159
+ }
160
+ exports.GotoError = GotoError;
150
161
  function sleep(ms) {
151
162
  return new Promise(resolve => setTimeout(resolve, ms));
152
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graceful-playwright",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
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": "^10.3.0",
61
+ "mocha": "^11.2.2",
62
62
  "npm-run-all": "^4.1.5",
63
- "playwright": "^1.50.0",
64
- "rimraf": "^5.0.5",
65
- "sinon": "^17.0.1",
66
- "ts-mocha": "^10.0.0",
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
  }