reset_viewport
Restore the browser's default viewport size and user agent after custom emulation.
Instructions
Reset viewport emulation to the browser's default size and user agent.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | No | Target tab ID (defaults to currently active tab) | |
| apiKey | No | API key for authentication if enabled |
Implementation Reference
- src/tools/emulation.ts:82-93 (handler)Handler function that sends a 'reset_viewport' command via WebSocket bridge and returns success/error response.
async ({ tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'reset_viewport', params: {}, tabId, apiKey, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: 'Viewport reset to default' }] }; } - src/tools/emulation.ts:78-81 (schema)Input schema for reset_viewport: accepts optional tabId and apiKey.
{ tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, - src/tools/emulation.ts:75-94 (registration)Registration of the 'reset_viewport' tool via server.tool() with name, description, schema, and handler.
server.tool( 'reset_viewport', 'Reset viewport emulation to the browser\'s default size and user agent.', { tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, async ({ tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'reset_viewport', params: {}, tabId, apiKey, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: 'Viewport reset to default' }] }; } ); - src/websocket-bridge.ts:63-103 (helper)WebSocketBridge.sendCommand sends the command over WebSocket to the Chrome extension which processes 'reset_viewport' on the browser side.
async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> { if (!this.isConnected()) { return { success: false, error: { code: 'NOT_CONNECTED', message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.', }, }; } const id = crypto.randomUUID(); const timeout = cmd.timeout ?? DEFAULT_TIMEOUT; return new Promise<BridgeResponse>((resolve, reject) => { const timer = setTimeout(() => { this.pending.delete(id); resolve({ success: false, error: { code: 'TIMEOUT', message: `Command '${cmd.command}' timed out after ${timeout}ms`, }, }); }, timeout); this.pending.set(id, { resolve, reject, timer }); const message = { id, type: 'request', command: cmd.command, params: cmd.params, tabId: cmd.tabId, apiKey: cmd.apiKey, timestamp: Date.now(), }; this.client!.send(JSON.stringify(message)); }); }