Skip to main content
Glama

Curupira

by drzln
test-cdp-connection.tsโ€ข3.57 kB
#!/usr/bin/env node /** * Test script to verify CDP connection from Curupira to Chrome * This script tests the complete flow from Curupira to the browserless Chrome instance */ import WebSocket from 'ws'; import fetch from 'node-fetch'; const CHROME_SERVICE_URL = process.env.CHROME_SERVICE_URL || 'http://chrome-headless.shared-services.svc.cluster.local:3000'; async function testCDPConnection() { console.log('๐Ÿงช Testing CDP connection to Chrome...'); console.log(`Chrome service URL: ${CHROME_SERVICE_URL}`); try { // Step 1: Test HTTP endpoint console.log('\n1๏ธโƒฃ Testing HTTP endpoint...'); const versionResponse = await fetch(`${CHROME_SERVICE_URL}/json/version`); if (!versionResponse.ok) { throw new Error(`HTTP request failed: ${versionResponse.status}`); } const versionData = await versionResponse.json(); console.log('โœ… HTTP endpoint working'); console.log(`Browser: ${versionData.Browser}`); console.log(`Protocol Version: ${versionData['Protocol-Version']}`); console.log(`Puppeteer Version: ${versionData['Puppeteer-Version']}`); // Step 2: Test WebSocket connection console.log('\n2๏ธโƒฃ Testing WebSocket connection...'); const wsUrl = CHROME_SERVICE_URL.replace('http://', 'ws://'); const ws = new WebSocket(wsUrl); await new Promise((resolve, reject) => { ws.on('open', () => { console.log('โœ… WebSocket connection established'); resolve(undefined); }); ws.on('error', (error) => { console.error('โŒ WebSocket error:', error); reject(error); }); setTimeout(() => { reject(new Error('WebSocket connection timeout')); }, 5000); }); // Step 3: Send CDP command console.log('\n3๏ธโƒฃ Sending CDP command...'); const cdpCommand = { id: 1, method: 'Target.getTargets', params: {} }; ws.send(JSON.stringify(cdpCommand)); await new Promise((resolve, reject) => { ws.on('message', (data) => { const response = JSON.parse(data.toString()); console.log('โœ… CDP response received'); console.log('Response:', JSON.stringify(response, null, 2)); resolve(undefined); }); setTimeout(() => { reject(new Error('CDP command timeout')); }, 5000); }); // Step 4: Close connection ws.close(); console.log('\nโœ… All tests passed! CDP connection is working.'); // Step 5: Test navigation console.log('\n4๏ธโƒฃ Testing page navigation...'); const puppeteerResponse = await fetch(`${CHROME_SERVICE_URL}/function`, { method: 'POST', headers: { 'Content-Type': 'application/javascript' }, body: ` module.exports = async ({ page }) => { await page.goto('http://novaskyn.staging.plo.quero.local', { waitUntil: 'networkidle2' }); const title = await page.title(); return { title, url: page.url() }; } ` }); if (puppeteerResponse.ok) { const result = await puppeteerResponse.json(); console.log('โœ… Page navigation successful'); console.log(`Page title: ${result.title}`); console.log(`Page URL: ${result.url}`); } else { console.log('โš ๏ธ Page navigation test skipped (browserless function API not available)'); } process.exit(0); } catch (error) { console.error('\nโŒ Test failed:', error); process.exit(1); } } // Run the test testCDPConnection();

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/drzln/curupira'

If you have feedback or need assistance with the MCP directory API, please join our Discord server