connect-browser-with-ws
Link a browser by establishing a WebSocket connection using its URL, enabling interaction through the AdsPower LocalAPI MCP Server for profile management and automation tasks.
Instructions
Connect the browser with the ws url
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| serialNumber | No | The serial number of the browser to connect | |
| userId | No | The browser id of the browser to connect | |
| wsUrl | Yes | The ws url of the browser, get from the open-browser tool content `ws.puppeteer` |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"serialNumber": {
"description": "The serial number of the browser to connect",
"type": "string"
},
"userId": {
"description": "The browser id of the browser to connect",
"type": "string"
},
"wsUrl": {
"description": "The ws url of the browser, get from the open-browser tool content `ws.puppeteer`",
"type": "string"
}
},
"required": [
"wsUrl"
],
"type": "object"
}
Implementation Reference
- src/handlers/automation.ts:9-16 (handler)The handler function for the 'connect-browser-with-ws' tool. It takes wsUrl, connects using the browser utility, and returns success or error message.async connectBrowserWithWs({ wsUrl }: CreateAutomationParams) { try { await browser.connectBrowserWithWs(wsUrl); return `Browser connected successfully with: ${wsUrl}`; } catch (error) { return `Failed to connect browser with: ${error?.toString()}`; } },
- src/utils/toolRegister.ts:50-51 (registration)Registration of the 'connect-browser-with-ws' tool on the MCP server, specifying name, description, input schema, and wrapped handler.server.tool('connect-browser-with-ws', 'Connect the browser with the ws url', schemas.createAutomationSchema.shape, wrapHandler(automationHandlers.connectBrowserWithWs));
- src/types/schemas.ts:167-171 (schema)Zod schema defining the input parameters for the connect-browser-with-ws tool, primarily wsUrl with optional userId and serialNumber.createAutomationSchema: z.object({ userId: z.string().optional().describe('The browser id of the browser to connect'), serialNumber: z.string().optional().describe('The serial number of the browser to connect'), wsUrl: z.string().describe('The ws url of the browser, get from the open-browser tool content `ws.puppeteer`') }).strict(),
- src/utils/browserBase.ts:43-50 (helper)Helper method in BrowserBase class that performs the actual WebSocket connection to the browser using Playwright's chromium.connectOverCDP.async connectBrowserWithWs(wsUrl: string) { this.browser = await chromium.connectOverCDP(wsUrl); const defaultContext = this.browser.contexts()[0]; this.page = defaultContext.pages()[0]; await this.page.bringToFront().catch((error) => { console.error('Failed to bring page to front', error); }); }