screenshot_chart
Capture the current chart pane as a base64-encoded PNG image for programmatic use or storage.
Instructions
Capture the chart pane as a base64-encoded PNG.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/screenshot.ts:26-39 (handler)The main handler for the screenshot_chart tool. Calls page.screenshotChart() and wraps errors in ToolExecutionError.
export async function screenshotChart( _input: z.infer<typeof screenshotChartInput>, page: TradingViewPage, ): Promise<z.infer<typeof screenshotChartOutput>> { try { return await page.screenshotChart(); } catch (cause) { throw new ToolExecutionError( 'screenshot_chart', 'Failed to capture chart screenshot.', cause, ); } } - src/tools/screenshot.ts:23-24 (schema)Input and output Zod schemas for screenshot_chart. Input is an empty strict object; output is the shared screenshotOutputSchema (format, data, width, height).
export const screenshotChartInput = z.object({}).strict(); export const screenshotChartOutput = screenshotOutputSchema; - src/tools/index.ts:141-148 (registration)Registration of screenshot_chart in the TOOLS array with name, description, input/output schemas, and the handler function.
// --- screenshot --- { name: 'screenshot_chart', description: 'Capture the chart pane as a base64-encoded PNG.', input: screenshotChartInput, output: screenshotChartOutput, handler: screenshotChart, }, - The low-level TradingViewPage method that performs the screenshot. Currently delegates to screenshotFull() as a v0.1 workaround; planned v0.2 improvement to clip to .chart-container.
async screenshotChart(): Promise<Screenshot> { // TODO(v0.2): clip to `.chart-container` bounding rect via CDP // Page.captureScreenshot `clip` parameter once selector is stable. return this.screenshotFull(); } - The screenshotFull() helper that screenshotChart currently delegates to. Uses CDP to capture full viewport as base64 PNG and returns Screenshot object.
/** Capture the full TradingView viewport as a base64 PNG. */ async screenshotFull(): Promise<Screenshot> { const data = await this.cdp.screenshot(); const dims = await this.cdp.evaluate<{ width: number; height: number }>( `({ width: window.innerWidth, height: window.innerHeight })`, ); return { format: 'png', data, width: dims.width, height: dims.height }; }