File size: 1,614 Bytes
668d995 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | /**
* Script to take a screenshot and list tabs
*/
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { join, dirname } from 'path';
import { fileURLToPath, URL } from 'url';
import { writeFileSync } from 'fs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const serverPath = join(__dirname, 'dist', 'index.js');
async function debug() {
const transport = new StdioClientTransport({
command: 'node',
args: [serverPath],
});
const client = new Client(
{
name: 'debug-client',
version: '1.0.0',
},
{
capabilities: {},
}
);
await client.connect(transport);
console.log('Navigating to Messenger...');
await client.callTool({
name: 'web_navigate',
arguments: { url: 'https://www.messenger.com' },
});
console.log('Taking screenshot...');
const result = await client.callTool({
name: 'web_screenshot',
arguments: { fullPage: true },
});
if (result.content && result.content[0].text) {
const data = JSON.parse(result.content[0].text);
if (data.base64) {
const screenshotPath = join(__dirname, 'messenger_login_check.png');
writeFileSync(screenshotPath, Buffer.from(data.base64, 'base64'));
console.log('Screenshot saved to:', screenshotPath);
}
}
await transport.close();
}
debug().catch(console.error);
|