nodejs_chromium 1.0.0 → 1.0.1

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 (2) hide show
  1. package/package.json +5 -5
  2. package/src/chrome.js +11 -7
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "nodejs_chromium",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "dependencies": {
10
- "nodejs_patch": ">1.0.5",
11
- "puppeteer": "^21.10.0"
8
+ },
9
+ "dependencies": {
10
+ "nodejs_patch": ">1.0.5",
11
+ "puppeteer": "^21.10.0"
12
12
  },
13
13
  "author": "fazo@qq.com",
14
14
  "license": "ISC"
package/src/chrome.js CHANGED
@@ -1,10 +1,10 @@
1
- const fs = require("fs");
1
+ const { writeFileSync: saveFile } = require("fs");
2
2
  const { parse: parseUrl } = require("url");
3
3
 
4
4
  module.exports = class {
5
5
  browser = null;
6
6
  page = null;
7
- response = [];
7
+ responseCall = null;
8
8
 
9
9
  constructor(browser, page, params) {
10
10
  this.browser = browser;
@@ -35,12 +35,16 @@ module.exports = class {
35
35
  });
36
36
 
37
37
  page.on('response', async res => {
38
+ if (!this.responseCall) return;
38
39
  let json = await this.parseResponse(res);
39
- if (json.method === 'POST') console.log(json);
40
- if (json.body) this.response.push(json);
40
+ this.responseCall(json);
41
41
  });
42
42
  }
43
43
 
44
+ response(call) {
45
+ this.responseCall = call;
46
+ }
47
+
44
48
  async open(url) {
45
49
  return await this.page.goto(url, { waitUntil: 'load' });
46
50
  }
@@ -67,7 +71,7 @@ module.exports = class {
67
71
 
68
72
  /**
69
73
  * page.on方法
70
- *
74
+ *
71
75
  * @param {Object} key
72
76
  * @param {Object} call
73
77
  */
@@ -152,7 +156,7 @@ module.exports = class {
152
156
  const body = await this.page.evaluate(() => {
153
157
  return document.documentElement.innerHTML;
154
158
  });
155
- await fs.writeFileSync(file, body);
159
+ await saveFile(file, body);
156
160
  }
157
161
  catch (e) {
158
162
  console.log('saveHtml Error:', e.parse());
@@ -162,7 +166,7 @@ module.exports = class {
162
166
  async saveCookies(file) {
163
167
  try {
164
168
  const cookies = await this.page.cookies();
165
- await fs.writeFileSync(file, JSON.stringify(cookies, null, 2));
169
+ await saveFile(file, JSON.stringify(cookies, null, 2));
166
170
  }
167
171
  catch (e) {
168
172
  console.log('saveHtml Error:', e.parse());