nodejs_chromium 1.1.5 → 1.1.6

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
@@ -6,6 +6,28 @@ global.__UA__ = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (K
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
8
 
9
+
10
+ async function NormalClose(path) {
11
+
12
+ const fs = require("fs");
13
+ /**
14
+ * 禁止显示【要恢复页面吗?chromium 未正确关闭。】
15
+ * PATH为chrome.userDataDir
16
+ * 修改`PATH\Default\Preferences`文件,
17
+ * 将`"profile.exit_type":“Crashed"` 改为`"Normal"`。
18
+ */
19
+ let file = `${path}/Default/Preferences`;
20
+ // console.log({file});
21
+ if (!fs.existsSync(file)) return;
22
+ let text = fs.readFileSync(file);
23
+ let json = JSON.parse(text);
24
+ //原值可能为:Crashed
25
+ json.profile.exit_type = 'Normal';
26
+ // console.log('json.profile.exit_type', json.profile.exit_type);
27
+ fs.writeFileSync(file, JSON.stringify(json));
28
+ }
29
+
30
+
9
31
  async function newBrowser(params) {
10
32
  try {
11
33
 
@@ -70,6 +92,7 @@ async function newBrowser(params) {
70
92
  '--disable-dev-shm-usage', //Linux系统中使用普通的文件系统缓存避免因为/dev/shm大小不足而导致的问题
71
93
  ]
72
94
  }
95
+ await NormalClose(option.userDataDir); //禁止显示【要恢复页面吗?chromium 未正确关闭。】
73
96
 
74
97
  if (proxy) option.defaultArgs.push(`--proxy-server=${proxy}`);
75
98
  if (incognito) option.args.push('--incognito', '--disable-infobars'); //使用无痕模式启动
@@ -95,7 +118,8 @@ async function newBrowser(params) {
95
118
  async function newChrome(params) {
96
119
  try {
97
120
  let {
98
- visible = false, //是否打开浏览器
121
+ id = 'myChrome',
122
+ visible = false, //是否打开浏览器
99
123
  mobile = false, //手机版
100
124
  ua = void 0, //若不指定ua则用__UA__
101
125
  cookies = null, //若cookies=false,则不处理cookies,不指定则由chrome处理,若=文件路径
@@ -120,7 +144,7 @@ async function newChrome(params) {
120
144
  navigator.__proto__ = newProto;
121
145
  });
122
146
 
123
- if (cookies !== false) cookies = `${option.userDataDir}/cookies.json`;
147
+ if (cookies !== false) cookies = `runtime/.cache/${id}/cookies.json`;
124
148
  const pageOption = { cookies, visible, abort, headers };
125
149
  return new chrome(browser, page, pageOption);
126
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs_chromium",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "for pupeteer chromium",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/chrome.js CHANGED
@@ -588,6 +588,7 @@ module.exports = class {
588
588
 
589
589
  value.type = await request.resourceType();
590
590
  // value.redirect = await response.redirectURL();
591
+ if (value.type === 'fetch') value.type = 'xhr';
591
592
  if (value.type === 'xhr') value.type = 'AJAX';
592
593
  value.url = await response.url();
593
594
  value.headers = { request: request.headers(), response: headers };
@@ -602,7 +603,7 @@ module.exports = class {
602
603
  if (headers['set-cookie']) value.cookies = await this.cookies.parse(headers['set-cookie']);
603
604
  value.remote = await response.remoteAddress(); //目标服务器
604
605
  if (value.status === 301 || value.status === 302) return value;
605
- if (['image', 'font', 'other', 'script', 'stylesheet', 'document', 'ping', 'fetch'].has(value.type)) return value;
606
+ if (['image', 'font', 'other', 'script', 'stylesheet', 'document', 'ping'].has(value.type)) return value;
606
607
  if (value.content) {
607
608
  if (value.content.startsWith('application/vnd')) return value;
608
609
  if (value.content.startsWith('application/xml')) return value;