nodejs_chromium 1.1.7 → 1.1.10
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 +10 -9
- package/package.json +1 -1
- package/src/chrome.js +3 -1
package/index.js
CHANGED
|
@@ -4,12 +4,10 @@ const chrome = require("./src/chrome.js");
|
|
|
4
4
|
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
|
+
const fs = require("fs");
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
async function NormalClose(path) {
|
|
11
|
-
|
|
12
|
-
const fs = require("fs");
|
|
13
11
|
/**
|
|
14
12
|
* 禁止显示【要恢复页面吗?chromium 未正确关闭。】
|
|
15
13
|
* PATH为chrome.userDataDir
|
|
@@ -94,21 +92,21 @@ async function newBrowser(params) {
|
|
|
94
92
|
]
|
|
95
93
|
}
|
|
96
94
|
|
|
97
|
-
if (proxy) option.
|
|
95
|
+
if (proxy) option.args.push(`--proxy-server=${proxy}`);
|
|
98
96
|
if (incognito) option.args.push('--incognito', '--disable-infobars'); //使用无痕模式启动
|
|
99
97
|
if (!cache) option.args.push('--disable-cache'); //禁缓存
|
|
100
98
|
if (path) option.executablePath = path; //指定chrome安装路径
|
|
101
99
|
|
|
102
|
-
browser = await puppeteer.launch(option);
|
|
103
|
-
|
|
100
|
+
const browser = await puppeteer.launch(option);
|
|
101
|
+
|
|
104
102
|
await NormalClose(option.userDataDir); //禁止显示【要恢复页面吗?chromium 未正确关闭。】
|
|
105
|
-
|
|
103
|
+
|
|
106
104
|
return browser;
|
|
107
105
|
}
|
|
108
106
|
catch (e) {
|
|
109
107
|
let mt = e.message.match(/\(ver\. (\d+\.\d+\.\d+\.\d+)\)/);
|
|
110
108
|
if (mt) {
|
|
111
|
-
return { error: `chrome(${mt})
|
|
109
|
+
return { error: `chrome(${mt[0]})未安装,请执行【npx puppeteer browsers install】以安装相应版本的chrome`, install: 1 };
|
|
112
110
|
}
|
|
113
111
|
else {
|
|
114
112
|
console.log('checkInstall', e.message);
|
|
@@ -130,7 +128,10 @@ async function newChrome(params) {
|
|
|
130
128
|
headers = {},
|
|
131
129
|
} = params;
|
|
132
130
|
|
|
133
|
-
await newBrowser(params);
|
|
131
|
+
const browser = await newBrowser(params);
|
|
132
|
+
if (browser.error) {
|
|
133
|
+
console.log({ browser })
|
|
134
|
+
}
|
|
134
135
|
|
|
135
136
|
// const version = await browser.version();
|
|
136
137
|
const page = (await browser.pages())[0];
|
package/package.json
CHANGED
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
|
-
|
|
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) {
|