MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / execute

Method execute

src/tools/browser/tools.ts:186–207  ·  view source on GitHub ↗
(args: z.infer<typeof ScreenshotArgs>, _ctx: ToolContext)

Source from the content-addressed store, hash-verified

184 argsSchema = ScreenshotArgs;
185
186 async execute(args: z.infer<typeof ScreenshotArgs>, _ctx: ToolContext): Promise<ToolResult> {
187 try {
188 const s = await getSession();
189 const dir = path.join(os.tmpdir(), 'qodex-screenshots');
190 await fs.mkdir(dir, { recursive: true });
191 const dest = args.path ?? path.join(dir, `shot-${Date.now()}.png`);
192 if (args.selector) {
193 const el = await s.page.$(args.selector);
194 if (!el) return { content: `[BROWSER_ERROR] selector not found: ${args.selector}`, isError: true };
195 await el.screenshot({ path: dest });
196 } else {
197 await s.page.screenshot({ path: dest, fullPage: args.full_page ?? false });
198 }
199 const stat = await fs.stat(dest);
200 const viewport = s.page.viewportSize();
201 return {
202 content: `Screenshot saved: ${dest}\n Size: ${(stat.size / 1024).toFixed(1)} KB${viewport ? `\n Viewport: ${viewport.width}x${viewport.height}` : ''}`,
203 };
204 } catch (e: any) {
205 return { content: `[BROWSER_ERROR] screenshot failed: ${e?.message ?? String(e)}`, isError: true };
206 }
207 }
208}
209
210const ConsoleArgs = z.object({

Callers

nothing calls this directly

Calls 1

getSessionFunction · 0.85

Tested by

no test coverage detected