@opentiny/webmcp-cli 0.0.9 → 0.1.0-alpha.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/dist/bin.js CHANGED
@@ -33,6 +33,38 @@ function shouldLaunchHeadless() {
33
33
  if (process.env.WEBMCP_HEADLESS === "0") return false;
34
34
  return process.env.WEBMCP_HEADLESS === "1" || process.env.CI === "true" || process.env.CI === "1";
35
35
  }
36
+ function shouldIgnoreCertificateErrors() {
37
+ return process.env.WEBMCP_IGNORE_CERTIFICATE_ERRORS === "1";
38
+ }
39
+ function buildChromeLaunchArgs(input) {
40
+ const launchArgs = [
41
+ `--remote-debugging-port=${input.cdpPort}`,
42
+ `--user-data-dir=${input.userDataDir}`,
43
+ "--no-first-run",
44
+ "--no-default-browser-check"
45
+ ];
46
+ if (input.headless) {
47
+ launchArgs.push(
48
+ "--headless=new",
49
+ "--no-sandbox",
50
+ "--disable-setuid-sandbox",
51
+ "--disable-gpu",
52
+ "--disable-dev-shm-usage"
53
+ );
54
+ }
55
+ const ignoreCertificateErrors = input.ignoreCertificateErrors ?? shouldIgnoreCertificateErrors();
56
+ if (ignoreCertificateErrors) {
57
+ launchArgs.push("--ignore-certificate-errors");
58
+ }
59
+ return launchArgs;
60
+ }
61
+ function buildPuppeteerConnectOptions(browserBaseUrl) {
62
+ return {
63
+ browserURL: browserBaseUrl,
64
+ defaultViewport: null,
65
+ ...shouldIgnoreCertificateErrors() ? { ignoreHTTPSErrors: true } : {}
66
+ };
67
+ }
36
68
  function readActivePortFromProfile(userDataDir) {
37
69
  try {
38
70
  const content = fs.readFileSync(path.join(userDataDir, "DevToolsActivePort"), "utf-8");
@@ -127,7 +159,7 @@ async function findAvailableCdpUrl(addresses, retries = 2) {
127
159
  async function connectPuppeteer(browserBaseUrl, attempt = 1, maxAttempts = 3) {
128
160
  try {
129
161
  return await promiseWithTimeout(
130
- puppeteer.connect({ browserURL: browserBaseUrl, defaultViewport: null }),
162
+ puppeteer.connect(buildPuppeteerConnectOptions(browserBaseUrl)),
131
163
  1e4,
132
164
  `puppeteer.connect to ${browserBaseUrl} timed out`
133
165
  );
@@ -202,21 +234,11 @@ async function startBrowserInBackground() {
202
234
  fs.unlinkSync(path.join(userDataDir, "DevToolsActivePort"));
203
235
  } catch {
204
236
  }
205
- const launchArgs = [
206
- `--remote-debugging-port=${cdpPort}`,
207
- `--user-data-dir=${userDataDir}`,
208
- "--no-first-run",
209
- "--no-default-browser-check"
210
- ];
211
- if (shouldLaunchHeadless()) {
212
- launchArgs.push(
213
- "--headless=new",
214
- "--no-sandbox",
215
- "--disable-setuid-sandbox",
216
- "--disable-gpu",
217
- "--disable-dev-shm-usage"
218
- );
219
- }
237
+ const launchArgs = buildChromeLaunchArgs({
238
+ cdpPort,
239
+ userDataDir,
240
+ headless: shouldLaunchHeadless()
241
+ });
220
242
  const child = spawn(
221
243
  browserInfo.path,
222
244
  launchArgs,
@@ -504,7 +526,7 @@ var init_package = __esm({
504
526
  "package.json"() {
505
527
  package_default = {
506
528
  name: "@opentiny/webmcp-cli",
507
- version: "0.0.9",
529
+ version: "0.1.0-alpha.1",
508
530
  type: "module",
509
531
  description: "WebMCP CLI for AI Agents to interact with browser via Puppeteer",
510
532
  main: "dist/index.js",
@@ -3544,11 +3566,20 @@ function handleCommandError(error, commandName, args) {
3544
3566
  }
3545
3567
  program.name("webmcp-cli").description(
3546
3568
  "WebMCP CLI \u2014 \u652F\u6301\u4E24\u79CD\u6D4F\u89C8\u5668\u8FDE\u63A5\u6A21\u5F0F\uFF1A\n --mode cdp\uFF08\u9ED8\u8BA4\uFF09: \u57FA\u4E8E Puppeteer + CDP \u76F4\u8FDE\u6D4F\u89C8\u5668\uFF08\u72EC\u7ACB profile\uFF09\n --mode wxt : \u57FA\u4E8E WebSocket + Chrome \u6269\u5C55\u6865\u63A5\uFF08\u590D\u7528\u7528\u6237\u6570\u636E\uFF09"
3547
- ).version(package_default.version).option("-w, --workspace <path>", "\u6307\u5B9A\u81EA\u5B9A\u4E49\u7684\u6D4F\u89C8\u5668\u5DE5\u4F5C\u7A7A\u95F4\uFF08\u7528\u6237\u914D\u7F6E\u76EE\u5F55\uFF09\u8DEF\u5F84\uFF0C\u4EC5 CDP \u6A21\u5F0F\u6709\u6548").hook("preAction", (thisCommand) => {
3569
+ ).version(package_default.version).option("-w, --workspace <path>", "\u6307\u5B9A\u81EA\u5B9A\u4E49\u7684\u6D4F\u89C8\u5668\u5DE5\u4F5C\u7A7A\u95F4\uFF08\u7528\u6237\u914D\u7F6E\u76EE\u5F55\uFF09\u8DEF\u5F84\uFF0C\u4EC5 CDP \u6A21\u5F0F\u6709\u6548").option(
3570
+ "--ignore-certificate-errors",
3571
+ "\u5173\u95ED\u53D7\u63A7\u6D4F\u89C8\u5668\u7684 HTTPS \u8BC1\u4E66\u6821\u9A8C\uFF08\u81EA\u7B7E\u540D\u3001\u8FC7\u671F\u6216\u4E3B\u673A\u540D\u4E0D\u5339\u914D\uFF09\u3002\u4E5F\u53EF\u8BBE\u7F6E\u73AF\u5883\u53D8\u91CF WEBMCP_IGNORE_CERTIFICATE_ERRORS=1\u3002\u9ED8\u8BA4\u4ECD\u6821\u9A8C\u3002\u4EC5 CDP \u6A21\u5F0F\u6709\u6548"
3572
+ ).hook("preAction", (thisCommand) => {
3548
3573
  const opts = thisCommand.opts();
3549
3574
  if (opts.workspace) {
3550
3575
  process.env.WEBMCP_WORKSPACE = opts.workspace;
3551
3576
  }
3577
+ if (opts.ignoreCertificateErrors) {
3578
+ process.env.WEBMCP_IGNORE_CERTIFICATE_ERRORS = "1";
3579
+ }
3580
+ if (process.env.WEBMCP_IGNORE_CERTIFICATE_ERRORS === "1") {
3581
+ console.error(pc2.yellow("\u5F53\u524D\u53D7\u63A7\u6D4F\u89C8\u5668\u5DF2\u5173\u95ED TLS \u8BC1\u4E66\u6821\u9A8C\u3002"));
3582
+ }
3552
3583
  });
3553
3584
  program.command("state").description("\u83B7\u53D6\u6D4F\u89C8\u5668\u5F53\u524D\u9875\u7B7E\u6216\u6307\u5B9A\u9875\u7B7E\u7684\u5BFC\u822A\u5143\u6570\u636E\uFF08url\u3001title\u3001webmcpTools\u3001\u6240\u6709\u9875\u7B7E\u5217\u8868\uFF09").option("-t, --tabid <id>", "\u6307\u5B9A\u9875\u7B7E\u7684 ID").action(async (options) => {
3554
3585
  const args = { tabid: parseTabId(options.tabid) };