nodejs_chromium 1.1.6 → 1.1.8

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 CHANGED
@@ -5,11 +5,10 @@ const { exec } = require("child_process");
5
5
  global.__UA__ = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36';
6
6
  const mob_ua = 'Mozilla/5.0 (Linux; Android 13;Build/TKQ1.220905.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36';
7
7
  let browser;
8
+ const fs = require("fs");
8
9
 
9
10
 
10
11
  async function NormalClose(path) {
11
-
12
- const fs = require("fs");
13
12
  /**
14
13
  * 禁止显示【要恢复页面吗?chromium 未正确关闭。】
15
14
  * PATH为chrome.userDataDir
@@ -21,8 +20,8 @@ async function NormalClose(path) {
21
20
  if (!fs.existsSync(file)) return;
22
21
  let text = fs.readFileSync(file);
23
22
  let json = JSON.parse(text);
24
- //原值可能为:Crashed
25
- json.profile.exit_type = 'Normal';
23
+ json.credentials_enable_service = false; //新增项,禁止保存密码
24
+ json.profile.exit_type = 'Normal'; //原值可能为:Crashed
26
25
  // console.log('json.profile.exit_type', json.profile.exit_type);
27
26
  fs.writeFileSync(file, JSON.stringify(json));
28
27
  }
@@ -82,6 +81,7 @@ async function newBrowser(params) {
82
81
  '--disable-web-security', //禁用浏览器的同源策略(Same-Origin Policy)和跨站请求伪造(CSRF)保护
83
82
  `--window-size=${width},${height}`,
84
83
  '--no-sandbox', //禁用沙箱模式
84
+ '--disable-password-saving', //禁止保存密码
85
85
  '--disable-autofill-backend', //禁止自动填充
86
86
  '--disable-setuid-sandbox', //禁用 setuid 沙箱。这是另一种沙箱模式,通常用于 Linux 系统上。
87
87
  // '--disable-infobars', //禁用自动化控制时显示的信息栏,告诉用户浏览器正在被自动化工具控制。
@@ -92,14 +92,16 @@ async function newBrowser(params) {
92
92
  '--disable-dev-shm-usage', //Linux系统中使用普通的文件系统缓存避免因为/dev/shm大小不足而导致的问题
93
93
  ]
94
94
  }
95
- await NormalClose(option.userDataDir); //禁止显示【要恢复页面吗?chromium 未正确关闭。】
96
95
 
97
- if (proxy) option.defaultArgs.push(`--proxy-server=${proxy}`);
96
+ if (proxy) option.args.push(`--proxy-server=${proxy}`);
98
97
  if (incognito) option.args.push('--incognito', '--disable-infobars'); //使用无痕模式启动
99
98
  if (!cache) option.args.push('--disable-cache'); //禁缓存
100
99
  if (path) option.executablePath = path; //指定chrome安装路径
101
100
 
102
101
  browser = await puppeteer.launch(option);
102
+
103
+ await NormalClose(option.userDataDir); //禁止显示【要恢复页面吗?chromium 未正确关闭。】
104
+
103
105
  return browser;
104
106
  }
105
107
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs_chromium",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "for pupeteer chromium",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/chrome.js CHANGED
@@ -311,7 +311,9 @@ module.exports = class {
311
311
  throw new Error(`${tag1} not exists`);
312
312
  }
313
313
  for (const elm of (await div.$$(tag2))) {
314
- call(elm, (await elm.evaluate(node => node.innerHTML)));
314
+ const html = await elm.evaluate(node => node.outerHTML);
315
+ const text = await elm.evaluate(node => node.innerHTML);
316
+ call(elm, { html, text });
315
317
  }
316
318
  }
317
319
  catch (e) {
@@ -399,12 +401,30 @@ module.exports = class {
399
401
  }
400
402
  }
401
403
 
404
+ /**
405
+ * delay=每键入一个字符延迟毫秒
406
+ */
407
+ async clear(el) {
408
+ try {
409
+ await this.page.$eval(el, ele => ele.value = '');
410
+ return this;
411
+ }
412
+ catch (e) {
413
+ console.log('[chrome.clear.Error]', e.message);
414
+ }
415
+ }
416
+
402
417
  /**
403
418
  * delay=每键入一个字符延迟毫秒
404
419
  */
405
420
  async input(el, value, delay = 1) {
406
421
  try {
407
- await this.page.type(el, value, { delay });
422
+ if (value === '') {
423
+ await this.page.$eval(el, ele => ele.value = '');
424
+ }
425
+ else {
426
+ await this.page.type(el, value, { delay });
427
+ }
408
428
  return this;
409
429
  }
410
430
  catch (e) {