nodejs_chromium 1.1.3 → 1.1.4
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 +11 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -10,31 +10,38 @@ async function newChrome(params) {
|
|
|
10
10
|
width = 1024, //宽
|
|
11
11
|
height = 768, //高
|
|
12
12
|
scale = 1, //缩放比例
|
|
13
|
+
touch = false, //支持触摸
|
|
13
14
|
mobile = false, //手机版
|
|
14
|
-
dumpio = false,
|
|
15
|
+
dumpio = false, //如果为 true,则将浏览器进程 stdout 和 stderr 通过管道传输到 process.stdout 和 process.stderr。
|
|
15
16
|
devtools = false, //打开devtools
|
|
16
17
|
cache = false, //禁用缓存
|
|
17
18
|
incognito = true, //使用无痕模式启动
|
|
18
19
|
path = void 0, //Chrome路径,linux下必填
|
|
19
20
|
slowMo = 1, //每一步停留时间
|
|
20
21
|
ua = void 0, //若不指定ua则用__UA__
|
|
22
|
+
env = void 0, //string,指定浏览器可见的环境变量。process.env 的内容。
|
|
21
23
|
proxy = null, //代理,如:https://proxy.com:789/
|
|
22
24
|
cookies = null, //若cookies=false,则不处理cookies,不指定则由chrome处理,若=文件路径
|
|
23
25
|
abort = [], //要禁止的类型,常见["font","image","ping","stylesheet","document","fetch","script","xhr"]
|
|
24
26
|
headers = {},
|
|
27
|
+
wait = true, //是否等待初始页面准备好。当用户明确禁用该功能时很有用(例如 Chrome 的 --no-startup-window)
|
|
28
|
+
timeout = 0, //等待浏览器启动的最长时间(以毫秒为单位)。 0 禁用超时。
|
|
25
29
|
} = params;
|
|
26
30
|
|
|
27
31
|
let option = {
|
|
28
32
|
userDataDir: `runtime/.cache/${id}`,
|
|
29
|
-
|
|
33
|
+
timeout, //最大允许超时间,默认为3000,最小215,一般不要设置
|
|
30
34
|
slowMo, //每一步停留时间,不能太大,否则会太慢,特别是在类似写入很多Cookies时,每写入一个都要等一下。
|
|
31
35
|
headless: visible ? false : 'new', //'new',设置是否在无头模式下运行浏览器,false=会启动浏览器,true=无界面
|
|
32
|
-
devtools
|
|
36
|
+
devtools, //打开调试
|
|
33
37
|
ignoreHTTPSErrors: true, //忽略 HTTPS 错误。屏蔽跳转不同域名的报错
|
|
34
38
|
dumpio, //是否将浏览器的标准输入/输出流(stdio)的内容输出到 Node.js 的 stdout 和 stderr。
|
|
39
|
+
env,
|
|
40
|
+
waitForInitialPage: wait,
|
|
35
41
|
defaultViewport: {
|
|
36
42
|
width,
|
|
37
43
|
height,
|
|
44
|
+
hasTouch: touch,
|
|
38
45
|
deviceScaleFactor: scale, //缩放比例
|
|
39
46
|
isMobile: !!mobile,
|
|
40
47
|
},
|
|
@@ -79,7 +86,7 @@ async function newChrome(params) {
|
|
|
79
86
|
navigator.__proto__ = newProto;
|
|
80
87
|
});
|
|
81
88
|
|
|
82
|
-
if (cookies !== false) cookies =
|
|
89
|
+
if (cookies !== false) cookies = `${option.userDataDir}/cookies.json`;
|
|
83
90
|
const pageOption = { cookies, visible, abort, headers };
|
|
84
91
|
return new chrome(browser, page, pageOption);
|
|
85
92
|
}
|