@szc-ft/mcp-szcd-client 0.19.0 → 0.19.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.
package/lib/browser-engine.js
CHANGED
|
@@ -361,16 +361,44 @@ export class BrowserEngine {
|
|
|
361
361
|
}
|
|
362
362
|
|
|
363
363
|
/**
|
|
364
|
-
* 动态加载 puppeteer-core
|
|
364
|
+
* 动态加载 puppeteer-core,缺失时自动安装
|
|
365
365
|
*/
|
|
366
366
|
async function loadPuppeteer() {
|
|
367
|
+
// 首次尝试直接加载
|
|
367
368
|
try {
|
|
368
369
|
const mod = await import("puppeteer-core");
|
|
369
370
|
return mod.default || mod;
|
|
370
|
-
} catch
|
|
371
|
+
} catch {
|
|
372
|
+
// 未安装,尝试自动安装
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
process.stderr.write("[browser-engine] puppeteer-core 未安装,正在自动安装...\n");
|
|
376
|
+
const { execSync } = await import("node:child_process");
|
|
377
|
+
|
|
378
|
+
const mirrorFlag = "--sharp_binary_host=https://npmmirror.com/mirrors/sharp";
|
|
379
|
+
const packages = "puppeteer-core pixelmatch pngjs sharp";
|
|
380
|
+
|
|
381
|
+
try {
|
|
382
|
+
execSync(`npm install --no-save ${mirrorFlag} ${packages}`, {
|
|
383
|
+
stdio: "inherit",
|
|
384
|
+
timeout: 120000,
|
|
385
|
+
});
|
|
386
|
+
} catch (installErr) {
|
|
371
387
|
const error = new Error(
|
|
372
|
-
`
|
|
388
|
+
`浏览器测试依赖安装失败。请手动执行:\n` +
|
|
389
|
+
` npm install puppeteer-core pixelmatch pngjs sharp --sharp_binary_host=https://npmmirror.com/mirrors/sharp\n` +
|
|
390
|
+
`原始错误:${installErr.message}`
|
|
373
391
|
);
|
|
392
|
+
error.code = "DEPENDENCY_INSTALL_FAILED";
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// 安装成功,重新加载
|
|
397
|
+
try {
|
|
398
|
+
const mod = await import("puppeteer-core");
|
|
399
|
+
return mod.default || mod;
|
|
400
|
+
} catch (err) {
|
|
401
|
+
const error = new Error(`puppeteer-core 安装后仍无法加载:${err.message}`);
|
|
374
402
|
error.code = "DEPENDENCY_MISSING";
|
|
375
403
|
throw error;
|
|
376
404
|
}
|
package/package.json
CHANGED