diff --git a/src/main.ts b/src/main.ts index a98c313..36129f6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,7 +10,7 @@ import { fileURLToPath } from 'node:url'; import { Command } from 'commander'; import chalk from 'chalk'; import { discoverClis, executeCommand } from './engine.js'; -import { type CliCommand, fullName, getRegistry, strategyLabel } from './registry.js'; +import { Strategy, type CliCommand, fullName, getRegistry, strategyLabel } from './registry.js'; import { render as renderOutput } from './output.js'; import { PlaywrightMCP } from './browser.js'; import { browserSession, DEFAULT_BROWSER_COMMAND_TIMEOUT, runWithTimeout } from './runtime.js'; @@ -101,7 +101,13 @@ for (const [, cmd] of registry) { try { let result: any; if (cmd.browser) { - result = await browserSession(PlaywrightMCP, async (page) => runWithTimeout(executeCommand(cmd, page, kwargs, actionOpts.verbose), { timeout: cmd.timeoutSeconds ?? DEFAULT_BROWSER_COMMAND_TIMEOUT, label: fullName(cmd) })); + result = await browserSession(PlaywrightMCP, async (page) => { + // Cookie/header strategies need same-origin context for credentialed fetch + if ((cmd.strategy === Strategy.COOKIE || cmd.strategy === Strategy.HEADER) && cmd.domain) { + try { await page.goto(`https://${cmd.domain}`); await page.wait(2); } catch {} + } + return runWithTimeout(executeCommand(cmd, page, kwargs, actionOpts.verbose), { timeout: cmd.timeoutSeconds ?? DEFAULT_BROWSER_COMMAND_TIMEOUT, label: fullName(cmd) }); + }); } else { result = await executeCommand(cmd, null, kwargs, actionOpts.verbose); } if (actionOpts.verbose && (!result || (Array.isArray(result) && result.length === 0))) { console.error(chalk.yellow(`[Verbose] Warning: Command returned an empty result. If the website structural API changed or requires authentication, check the network or update the adapter.`));