graceful-playwright 1.5.0 → 1.6.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 +18 -0
- package/core.d.ts +6 -0
- package/core.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,6 +122,24 @@ export type GotoErrorDetails = {
|
|
|
122
122
|
}
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
Helper Function: `getStealthChromiumArgs`
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
export function getStealthChromiumArgs(options: {
|
|
129
|
+
noSandbox?: boolean
|
|
130
|
+
/** default is a version of Mac OS */
|
|
131
|
+
userAgent?: string
|
|
132
|
+
}): string[]
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
It returns list of arguments that can be used in `chromium.launch()` and `chromium.launchPersistentContext()`:
|
|
136
|
+
|
|
137
|
+
- `--no-sandbox` (conditionally)
|
|
138
|
+
- `--disable-setuid-sandbox` (conditionally)
|
|
139
|
+
- `--disable-dev-shm-usage`
|
|
140
|
+
- `--user-agent=${userAgent}`
|
|
141
|
+
- `--disable-blink-features=AutomationControlled`
|
|
142
|
+
|
|
125
143
|
## License
|
|
126
144
|
|
|
127
145
|
This project is licensed with [BSD-2-Clause](./LICENSE)
|
package/core.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Browser, BrowserContext, Page } from 'playwright';
|
|
2
|
+
/** can be used in args by `chromium.launch()` and `chromium.launchPersistentContext()` */
|
|
3
|
+
export declare function getStealthChromiumArgs(options?: {
|
|
4
|
+
noSandbox?: boolean;
|
|
5
|
+
/** default is a version of Mac OS */
|
|
6
|
+
userAgent?: string;
|
|
7
|
+
}): string[];
|
|
2
8
|
export declare class GracefulPage {
|
|
3
9
|
options: {
|
|
4
10
|
from: Browser | BrowserContext;
|
package/core.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GotoError = exports.GracefulPage = void 0;
|
|
4
|
+
exports.getStealthChromiumArgs = getStealthChromiumArgs;
|
|
4
5
|
exports.parseRetryAfter = parseRetryAfter;
|
|
6
|
+
/** can be used in args by `chromium.launch()` and `chromium.launchPersistentContext()` */
|
|
7
|
+
function getStealthChromiumArgs(options = {}) {
|
|
8
|
+
let userAgent = options.userAgent ||
|
|
9
|
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36';
|
|
10
|
+
let args = [];
|
|
11
|
+
if (options.noSandbox) {
|
|
12
|
+
args.push('--no-sandbox', '--disable-setuid-sandbox');
|
|
13
|
+
}
|
|
14
|
+
args.push('--disable-dev-shm-usage', `--user-agent=${userAgent}`, '--disable-blink-features=AutomationControlled');
|
|
15
|
+
return args;
|
|
16
|
+
}
|
|
5
17
|
class GracefulPage {
|
|
6
18
|
options;
|
|
7
19
|
constructor(options) {
|
|
@@ -71,6 +83,7 @@ class GracefulPage {
|
|
|
71
83
|
let isKnownError = message.includes(`Navigation to ${urlStr} is interrupted by another navigation to ${urlStr}`) ||
|
|
72
84
|
// e.g. 'Timeout 30000ms exceeded'
|
|
73
85
|
/Timeout [\w]+ exceeded/.test(message) ||
|
|
86
|
+
message.includes('ERR_INTERNET_DISCONNECTED') ||
|
|
74
87
|
message.includes('ERR_NETWORK_CHANGED') ||
|
|
75
88
|
message.includes('ERR_CONNECTION_RESET') ||
|
|
76
89
|
message.includes('ERR_SOCKET_NOT_CONNECTED') ||
|