nodejs_chromium 1.1.25 → 1.1.26
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/index.js +14 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -71,6 +71,7 @@ async function newBrowser(params) {
|
|
|
71
71
|
proxy = null, //代理,如:https://proxy.com:789/
|
|
72
72
|
wait = true, //是否等待初始页面准备好。当用户明确禁用该功能时很有用(例如 Chrome 的 --no-startup-window)
|
|
73
73
|
timeout = 0, //等待浏览器启动的最长时间(以毫秒为单位)。 0 禁用超时。
|
|
74
|
+
protocolTimeout = 0, //CDP协议超时时间(毫秒),默认0使用Puppeteer内置默认值(180000)。如遇到ProtocolError超时可增大此值。
|
|
74
75
|
} = params;
|
|
75
76
|
|
|
76
77
|
const userDataDir = `runtime/.cache/${id}`;
|
|
@@ -85,6 +86,7 @@ async function newBrowser(params) {
|
|
|
85
86
|
ignoreHTTPSErrors: true, //忽略 HTTPS 错误。屏蔽跳转不同域名的报错
|
|
86
87
|
dumpio, //是否将浏览器的标准输入/输出流(stdio)的内容输出到 Node.js 的 stdout 和 stderr。
|
|
87
88
|
env,
|
|
89
|
+
protocolTimeout,
|
|
88
90
|
waitForInitialPage: wait,
|
|
89
91
|
defaultViewport: {
|
|
90
92
|
width,
|
|
@@ -150,7 +152,7 @@ async function newBrowser(params) {
|
|
|
150
152
|
|
|
151
153
|
async function newChrome(params) {
|
|
152
154
|
try {
|
|
153
|
-
|
|
155
|
+
const {
|
|
154
156
|
id = 'myChrome',
|
|
155
157
|
visible = false, //是否打开浏览器
|
|
156
158
|
mobile = false, //手机版
|
|
@@ -160,7 +162,8 @@ async function newChrome(params) {
|
|
|
160
162
|
headers = {},
|
|
161
163
|
index = 0, //同一浏览器的第几个窗口
|
|
162
164
|
interception = false, //允许拦截
|
|
163
|
-
device = null //设备类型
|
|
165
|
+
device = null, //设备类型
|
|
166
|
+
webdriver = null, //删除 navigator.webdriver字段
|
|
164
167
|
} = params;
|
|
165
168
|
|
|
166
169
|
if (!browser) {
|
|
@@ -186,14 +189,16 @@ async function newChrome(params) {
|
|
|
186
189
|
await page.emulate(device); //必须要放在setUserAgent后面
|
|
187
190
|
}
|
|
188
191
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
if (webdriver !== false) {
|
|
193
|
+
await page.evaluateOnNewDocument(() => {
|
|
194
|
+
const newProto = navigator.__proto__;
|
|
195
|
+
delete newProto.webdriver; //删除 navigator.webdriver字段,防止检测到自动化行为
|
|
196
|
+
navigator.__proto__ = newProto;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
194
199
|
|
|
195
|
-
|
|
196
|
-
const pageOption = { cookies, visible, abort, headers, device };
|
|
200
|
+
const cook = (cookies === false) ? `runtime/.cache/${id}/cookies.json` : cookies;
|
|
201
|
+
const pageOption = { cookies: cook, visible, abort, headers, device };
|
|
197
202
|
return new chrome(browser, page, pageOption);
|
|
198
203
|
}
|
|
199
204
|
catch (err) {
|