nodejs_chromium 1.1.6 → 1.1.7

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