adspower-browser 2.1.0 → 2.1.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.
@@ -1,30 +1,91 @@
1
1
  "use strict";
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __commonJS = (cb, mod) => function __require() {
4
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
5
+ };
6
+
7
+ // src/core/winHideChildProcessLogic.js
8
+ var require_winHideChildProcessLogic = __commonJS({
9
+ "src/core/winHideChildProcessLogic.js"(exports2, module2) {
10
+ "use strict";
11
+ var path = require("path");
12
+ var CONSOLE_EXECUTABLES = /^(cmd|powershell|pwsh|wmic|tasklist|reg|findstr|where|whoami|systeminfo|netstat|sc|net|chcp|hostname|conhost)(\.exe)?$/i;
13
+ var BROWSER_EXECUTABLES = /^(sunbrowser|flowerbrowser|chrome|chromium|msedge|firefox|brave|opera)(\.exe)?$/i;
14
+ function getExecutableBaseName(command) {
15
+ const trimmed = String(command).trim();
16
+ let executable = trimmed;
17
+ const quotedMatch = trimmed.match(/^"([^"]+)"|^'([^']+)'/);
18
+ if (quotedMatch) {
19
+ executable = quotedMatch[1] || quotedMatch[2];
20
+ } else {
21
+ executable = trimmed.split(/\s+/)[0] || trimmed;
22
+ }
23
+ executable = executable.replace(/^["']|["']$/g, "");
24
+ return path.basename(executable.replace(/\\/g, "/")).toLowerCase();
25
+ }
26
+ function shouldHideForSpawn(command, options) {
27
+ if (options?.windowsHide === false) {
28
+ return false;
29
+ }
30
+ const base = getExecutableBaseName(command);
31
+ if (BROWSER_EXECUTABLES.test(base)) {
32
+ return false;
33
+ }
34
+ if (CONSOLE_EXECUTABLES.test(base)) {
35
+ return true;
36
+ }
37
+ if (options?.shell) {
38
+ return true;
39
+ }
40
+ if (/\.(cmd|bat)$/i.test(base)) {
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+ function withWindowsHideForExec2(options) {
46
+ if (typeof options === "object" && options !== null && !Array.isArray(options)) {
47
+ if (options.windowsHide === false) {
48
+ return options;
49
+ }
50
+ return { ...options, windowsHide: true };
51
+ }
52
+ return { windowsHide: true };
53
+ }
54
+ function withWindowsHideForSpawn2(command, options) {
55
+ const opts = typeof options === "object" && options !== null && !Array.isArray(options) ? { ...options } : {};
56
+ if (!shouldHideForSpawn(command, opts)) {
57
+ return opts;
58
+ }
59
+ return { ...opts, windowsHide: true };
60
+ }
61
+ module2.exports = {
62
+ CONSOLE_EXECUTABLES,
63
+ BROWSER_EXECUTABLES,
64
+ getExecutableBaseName,
65
+ shouldHideForSpawn,
66
+ withWindowsHideForExec: withWindowsHideForExec2,
67
+ withWindowsHideForSpawn: withWindowsHideForSpawn2
68
+ };
69
+ }
70
+ });
2
71
 
3
72
  // src/core/winHideChildProcess.js
4
73
  if (process.platform !== "win32") {
5
74
  return;
6
75
  }
7
76
  var cp = require("child_process");
8
- function withWindowsHide(options) {
9
- if (typeof options === "object" && options !== null && !Array.isArray(options)) {
10
- if (options.windowsHide === false) {
11
- return options;
12
- }
13
- return { ...options, windowsHide: true };
14
- }
15
- return { windowsHide: true };
16
- }
77
+ var { withWindowsHideForExec, withWindowsHideForSpawn } = require_winHideChildProcessLogic();
17
78
  function normalizeExecArgs(options, callback) {
18
79
  if (typeof options === "function") {
19
- return { options: { windowsHide: true }, callback: options };
80
+ return { options: withWindowsHideForExec({}), callback: options };
20
81
  }
21
- return { options: withWindowsHide(options || {}), callback };
82
+ return { options: withWindowsHideForExec(options || {}), callback };
22
83
  }
23
- function normalizeSpawnArgs(args, options) {
84
+ function normalizeSpawnArgs(command, args, options) {
24
85
  if (Array.isArray(args)) {
25
- return { args, options: withWindowsHide(options || {}) };
86
+ return { args, options: withWindowsHideForSpawn(command, options || {}) };
26
87
  }
27
- return { args: [], options: withWindowsHide(args || {}) };
88
+ return { args: [], options: withWindowsHideForSpawn(command, args || {}) };
28
89
  }
29
90
  var origExec = cp.exec.bind(cp);
30
91
  cp.exec = function exec(cmd, options, callback) {
@@ -33,15 +94,15 @@ cp.exec = function exec(cmd, options, callback) {
33
94
  };
34
95
  var origExecSync = cp.execSync.bind(cp);
35
96
  cp.execSync = function execSync(cmd, options) {
36
- return origExecSync(cmd, withWindowsHide(options || {}));
97
+ return origExecSync(cmd, withWindowsHideForExec(options || {}));
37
98
  };
38
99
  var origSpawn = cp.spawn.bind(cp);
39
100
  cp.spawn = function spawn(command, args, options) {
40
- const normalized = normalizeSpawnArgs(args, options);
101
+ const normalized = normalizeSpawnArgs(command, args, options);
41
102
  return origSpawn(command, normalized.args, normalized.options);
42
103
  };
43
104
  var origSpawnSync = cp.spawnSync.bind(cp);
44
105
  cp.spawnSync = function spawnSync(command, args, options) {
45
- const normalized = normalizeSpawnArgs(args, options);
106
+ const normalized = normalizeSpawnArgs(command, args, options);
46
107
  return origSpawnSync(command, normalized.args, normalized.options);
47
108
  };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ // src/core/winHideChildProcessLogic.js
4
+ var path = require("path");
5
+ var CONSOLE_EXECUTABLES = /^(cmd|powershell|pwsh|wmic|tasklist|reg|findstr|where|whoami|systeminfo|netstat|sc|net|chcp|hostname|conhost)(\.exe)?$/i;
6
+ var BROWSER_EXECUTABLES = /^(sunbrowser|flowerbrowser|chrome|chromium|msedge|firefox|brave|opera)(\.exe)?$/i;
7
+ function getExecutableBaseName(command) {
8
+ const trimmed = String(command).trim();
9
+ let executable = trimmed;
10
+ const quotedMatch = trimmed.match(/^"([^"]+)"|^'([^']+)'/);
11
+ if (quotedMatch) {
12
+ executable = quotedMatch[1] || quotedMatch[2];
13
+ } else {
14
+ executable = trimmed.split(/\s+/)[0] || trimmed;
15
+ }
16
+ executable = executable.replace(/^["']|["']$/g, "");
17
+ return path.basename(executable.replace(/\\/g, "/")).toLowerCase();
18
+ }
19
+ function shouldHideForSpawn(command, options) {
20
+ if (options?.windowsHide === false) {
21
+ return false;
22
+ }
23
+ const base = getExecutableBaseName(command);
24
+ if (BROWSER_EXECUTABLES.test(base)) {
25
+ return false;
26
+ }
27
+ if (CONSOLE_EXECUTABLES.test(base)) {
28
+ return true;
29
+ }
30
+ if (options?.shell) {
31
+ return true;
32
+ }
33
+ if (/\.(cmd|bat)$/i.test(base)) {
34
+ return true;
35
+ }
36
+ return false;
37
+ }
38
+ function withWindowsHideForExec(options) {
39
+ if (typeof options === "object" && options !== null && !Array.isArray(options)) {
40
+ if (options.windowsHide === false) {
41
+ return options;
42
+ }
43
+ return { ...options, windowsHide: true };
44
+ }
45
+ return { windowsHide: true };
46
+ }
47
+ function withWindowsHideForSpawn(command, options) {
48
+ const opts = typeof options === "object" && options !== null && !Array.isArray(options) ? { ...options } : {};
49
+ if (!shouldHideForSpawn(command, opts)) {
50
+ return opts;
51
+ }
52
+ return { ...opts, windowsHide: true };
53
+ }
54
+ module.exports = {
55
+ CONSOLE_EXECUTABLES,
56
+ BROWSER_EXECUTABLES,
57
+ getExecutableBaseName,
58
+ shouldHideForSpawn,
59
+ withWindowsHideForExec,
60
+ withWindowsHideForSpawn
61
+ };
package/cli/index.js CHANGED
@@ -907,12 +907,16 @@ var API_ENDPOINTS = {
907
907
  GET_KERNEL_LIST: LOCAL_API_CONTRACTS["get-kernel-list"].path,
908
908
  UPDATE_PATCH: LOCAL_API_CONTRACTS["update-patch"].path
909
909
  };
910
+ var createClientHeaders = (apiKey) => ({
911
+ ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
912
+ "x-mcp-client": "mcp"
913
+ });
910
914
  var apiClient = import_axios2.default.create({
911
- headers: API_KEY ? { "Authorization": `Bearer ${API_KEY}` } : {}
915
+ headers: createClientHeaders(API_KEY)
912
916
  });
913
917
  var getApiClient = () => {
914
918
  const client = import_axios2.default.create({
915
- headers: CONFIG.apiKey ? { "Authorization": `Bearer ${CONFIG.apiKey}` } : {}
919
+ headers: createClientHeaders(CONFIG.apiKey)
916
920
  });
917
921
  client.interceptors.request.use(async (config2) => {
918
922
  if (isLocalApiRequestUrl(config2.url)) {
@@ -1312,6 +1316,51 @@ function resolveOpenBrowserHeadless(params, env, platform) {
1312
1316
  };
1313
1317
  }
1314
1318
 
1319
+ // ../core/src/utils/systemVer.ts
1320
+ var import_os = __toESM(require("os"));
1321
+ function getUaSystemVersionFromOs(info = {}) {
1322
+ const platform = info.platform ?? import_os.default.platform();
1323
+ const release = info.release ?? import_os.default.release();
1324
+ if (platform === "linux") {
1325
+ return "Linux";
1326
+ }
1327
+ if (platform === "win32") {
1328
+ return matchWindowsVersion(release);
1329
+ }
1330
+ if (platform === "darwin") {
1331
+ return matchMacVersion(release);
1332
+ }
1333
+ return null;
1334
+ }
1335
+ function matchWindowsVersion(release) {
1336
+ const [majorStr, minorStr = "0", buildStr = "0"] = release.split(".");
1337
+ const major = Number(majorStr);
1338
+ const minor = Number(minorStr);
1339
+ const build = Number(buildStr);
1340
+ if (major === 6) {
1341
+ if (minor === 1) return "Windows 7";
1342
+ if (minor === 2 || minor === 3) return "Windows 8";
1343
+ }
1344
+ if (major === 10 && minor === 0) {
1345
+ return build >= 22e3 ? "Windows 11" : "Windows 10";
1346
+ }
1347
+ return "Windows";
1348
+ }
1349
+ function matchMacVersion(release) {
1350
+ const darwinMajor = Number(release.split(".")[0]);
1351
+ if (darwinMajor < 20) return "Mac OS X 10";
1352
+ const darwinToMac = {
1353
+ 20: "Mac OS X 11",
1354
+ 21: "Mac OS X 12",
1355
+ 22: "Mac OS X 13",
1356
+ 23: "Mac OS X 14",
1357
+ 24: "Mac OS X 15",
1358
+ 25: "Mac OS X 26"
1359
+ // macOS Tahoe 26,Darwin 仍为 25.x
1360
+ };
1361
+ return darwinToMac[darwinMajor] ?? "Mac OS X";
1362
+ }
1363
+
1315
1364
  // ../core/src/handlers/browser.ts
1316
1365
  var browserHandlers = {
1317
1366
  async openBrowser(params) {
@@ -1336,7 +1385,23 @@ var browserHandlers = {
1336
1385
  throw new Error(response.data.msg);
1337
1386
  },
1338
1387
  async createBrowser(params) {
1339
- const requestBody = buildRequestBodyFor("create-browser", params);
1388
+ let resolvedParams = params;
1389
+ if (!params.fingerprint_config?.random_ua?.ua_system_version) {
1390
+ const uaSystemVersion = getUaSystemVersionFromOs();
1391
+ if (uaSystemVersion) {
1392
+ resolvedParams = {
1393
+ ...params,
1394
+ fingerprint_config: {
1395
+ ...params.fingerprint_config,
1396
+ random_ua: {
1397
+ ...params.fingerprint_config?.random_ua,
1398
+ ua_system_version: [uaSystemVersion]
1399
+ }
1400
+ }
1401
+ };
1402
+ }
1403
+ }
1404
+ const requestBody = buildRequestBodyFor("create-browser", resolvedParams);
1340
1405
  const response = await getApiClient().post(`${getLocalApiBase()}${API_ENDPOINTS.CREATE_BROWSER}`, requestBody);
1341
1406
  if (response.data.code === 0) {
1342
1407
  return JSON.stringify(response.data.data, null, 2);
@@ -1598,7 +1663,7 @@ var tagHandlers = {
1598
1663
 
1599
1664
  // ../core/src/handlers/automation.ts
1600
1665
  var import_path2 = __toESM(require("path"));
1601
- var import_os = __toESM(require("os"));
1666
+ var import_os2 = __toESM(require("os"));
1602
1667
 
1603
1668
  // ../core/src/utils/browserBase.ts
1604
1669
  var import_playwright_core = require("playwright-core");
@@ -1651,7 +1716,7 @@ var BrowserBase = class {
1651
1716
  var browserBase_default = new BrowserBase();
1652
1717
 
1653
1718
  // ../core/src/handlers/automation.ts
1654
- var defaultDownloadsPath = import_path2.default.join(import_os.default.homedir(), "Downloads");
1719
+ var defaultDownloadsPath = import_path2.default.join(import_os2.default.homedir(), "Downloads");
1655
1720
 
1656
1721
  // ../core/src/handlers/kernel.ts
1657
1722
  var kernelHandlers = {
@@ -1805,6 +1870,7 @@ var randomUaConfigSchema = import_zod.z.object({
1805
1870
  "Mac OS X 13",
1806
1871
  "Mac OS X 14",
1807
1872
  "Mac OS X 15",
1873
+ "Mac OS X 26",
1808
1874
  "Mac OS X",
1809
1875
  "Windows",
1810
1876
  "iOS",
@@ -2212,7 +2278,7 @@ var schemas = {
2212
2278
  ipchecker: import_zod.z.enum(["ip2location", "ipapi", "ipfoxy"]).optional().describe("IP query channel"),
2213
2279
  category_id: import_zod.z.string().optional().describe("The category id of the browser, you can use the get-application-list tool to get the application list"),
2214
2280
  profile_tag_ids: import_zod.z.array(import_zod.z.string()).max(30).optional().describe('Tag IDs to assign to the profile, max 30 tags per profile. Example: ["tag1","tag2"]'),
2215
- fingerprint_config: fingerprintConfigSchema.optional().default({ random_ua: { ua_system_version: ["Windows"] }, browser_kernel_config: { version: "latest", type: "chrome" } }),
2281
+ fingerprint_config: fingerprintConfigSchema.optional().default({ browser_kernel_config: { version: "latest", type: "chrome" } }),
2216
2282
  platform_account: platformAccountSchema
2217
2283
  }).strict(),
2218
2284
  updateBrowserSchema: import_zod.z.object({
@@ -3050,9 +3116,6 @@ var startChild = (type) => {
3050
3116
  }
3051
3117
  if (text === "restart") {
3052
3118
  child && child.kill("SIGKILL");
3053
- store.setStoreValue("status", "restarting");
3054
- startChild("2").catch(() => {
3055
- });
3056
3119
  }
3057
3120
  if (text.indexOf("INTRANET_$$_") > -1) {
3058
3121
  const arr = text.split("_$$_");
@@ -3084,18 +3147,9 @@ var startChild = (type) => {
3084
3147
  process.exit(0);
3085
3148
  });
3086
3149
  child.on("exit", async (code, signal) => {
3087
- if (signal === "SIGKILL") {
3088
- await browsersKill();
3089
- store.clear();
3090
- removePidFile();
3091
- } else {
3092
- child = null;
3093
- await sleepTime(500);
3094
- startChild("2").then(() => {
3095
- }).catch(() => {
3096
- logError("[!] Restart failed");
3097
- });
3098
- }
3150
+ await browsersKill();
3151
+ store.clear();
3152
+ removePidFile();
3099
3153
  });
3100
3154
  timer = setTimeout(() => {
3101
3155
  child && child.kill("SIGKILL");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adspower-browser",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "main": "cli/index.js",
5
5
  "type": "commonjs",
6
6
  "bin": {