nodejs_chromium 1.0.6 → 1.0.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.
Files changed (3) hide show
  1. package/index.js +2 -2
  2. package/package.json +1 -1
  3. package/src/chrome.js +17 -11
package/index.js CHANGED
@@ -6,7 +6,7 @@ global.__UA__ = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (K
6
6
  async function newChrome(params) {
7
7
  let {
8
8
  id = 'myChrome',
9
- view = false,
9
+ visible = false,
10
10
  width = 1024,
11
11
  height = 768,
12
12
  scale = 1,
@@ -23,7 +23,7 @@ async function newChrome(params) {
23
23
  userDataDir: `runtime/template/${id}`,
24
24
  // timeout: 500,//最大允许超时间,默认为3000,最小215,一般不要设置
25
25
  slowMo, //每一步停留时间,不能太大,否则会太慢,特别是在类似写入很多Cookies时,每写入一个都要等一下。
26
- headless: view ? false : 'new', //'new',设置是否在无头模式下运行浏览器,false=会启动浏览器,true=无界面
26
+ headless: visible ? false : 'new', //'new',设置是否在无头模式下运行浏览器,false=会启动浏览器,true=无界面
27
27
  devtools: !!debug, //打开调试
28
28
  ignoreHTTPSErrors: true, //忽略 HTTPS 错误。屏蔽跳转不同域名的报错
29
29
  ignoreDefaultArgs: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs_chromium",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/chrome.js CHANGED
@@ -16,15 +16,15 @@ module.exports = class {
16
16
  page = null;
17
17
  responseCall = null;
18
18
  requestCall = null;
19
- isFrame = false;
20
- visible = false;
19
+ isFrame = false; //是不是在iFrame中
20
+ visible = false; //是否可见,也就是有没有启动窗口
21
21
  params = {};
22
22
 
23
23
  constructor(browser, page, params, isFrame = false) {
24
24
  this.browser = browser;
25
25
  this.page = page;
26
26
  this.params = params;
27
- this.visible = !!params.view;
27
+ this.visible = !!params.visible;
28
28
  this.isFrame = !!isFrame;
29
29
  this.doListening(params);
30
30
  }
@@ -132,6 +132,10 @@ module.exports = class {
132
132
  }
133
133
  }
134
134
 
135
+ /**
136
+ * 按tag创建当前窗口中的某个iFrame
137
+ * @param {Object} tag
138
+ */
135
139
  async iframe(tag) {
136
140
  try {
137
141
  const frame = await (await this.page.$(tag)).contentFrame();
@@ -175,7 +179,9 @@ module.exports = class {
175
179
  return this.page.url();
176
180
  }
177
181
 
178
-
182
+ /**
183
+ * 重新设置尺寸
184
+ */
179
185
  async size(width = 1024, height = 768) {
180
186
  await this.page.setViewport({ width, height });
181
187
  return this;
@@ -279,9 +285,9 @@ module.exports = class {
279
285
  */
280
286
  async display(tag, show) {
281
287
  try {
282
- // const element = await this.page.querySelector(tag);
283
- // element.style.display = (!!show) ? '' : 'none';
284
- (await this.page.querySelector(tag)).style.display = (!!show) ? '' : 'none';
288
+ const element = await this.page.querySelector(tag);
289
+ if (!element) throw new Error(`${tag} not exists`);
290
+ element.style.display = (!!show) ? '' : 'none';
285
291
  return this;
286
292
  }
287
293
  catch (e) {
@@ -376,7 +382,6 @@ module.exports = class {
376
382
  async waiting(time) {
377
383
  return await this.sleep(time);
378
384
  }
379
-
380
385
  async sleep(time) {
381
386
  if (time < 100) time = time * 1000;
382
387
  try {
@@ -485,7 +490,7 @@ module.exports = class {
485
490
  return this;
486
491
  }
487
492
  catch (e) {
488
- console.log('[chrome.saveHtml.Error]', e.parse());
493
+ console.log('[chrome.saveHtml.Error]', e.message);
489
494
  }
490
495
  }
491
496
 
@@ -549,6 +554,7 @@ module.exports = class {
549
554
  }
550
555
  catch (e) {
551
556
  console.log('[chrome.setCookies.Error]', e.message);
557
+ console.log(cookies);
552
558
  }
553
559
  }
554
560
 
@@ -569,7 +575,7 @@ module.exports = class {
569
575
  return this;
570
576
  }
571
577
  catch (e) {
572
- console.log('[chrome.saveCookies.Error]', e.parse());
578
+ console.log('[chrome.saveCookies.Error]', e.message);
573
579
  }
574
580
  }
575
581
 
@@ -655,7 +661,7 @@ module.exports = class {
655
661
  * @param {Object} strCookies
656
662
  */
657
663
  async parseCookies(strCookies) {
658
- return await strCookies.split("\n").map((ls, i) => {
664
+ return await strCookies.split("\n").map((ls) => {
659
665
  let value = {};
660
666
  ls.split(';').map((ln, j) => {
661
667
  // console.log(ln);