Skip to main content
Glama
Rainmen-xia

Chrome Debug MCP Server

by Rainmen-xia

navigate_to

Navigate Chrome to a specified URL, intelligently reusing existing tabs for the same domain to manage browser sessions efficiently.

Instructions

导航到指定URL,智能管理标签页(相同域名复用标签页)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes要导航到的URL

Implementation Reference

  • The core handler function implementing 'navigate_to' logic: intelligently navigates to the given URL by reusing existing tabs for the same root domain or creating new ones, with robust loading waits and error handling.
    async navigateToUrl(url: string): Promise<BrowserActionResult> { if (!this.browser) { return { success: false, error: "浏览器未启动" }; } // 移除尾部斜杠进行比较 const normalizedNewUrl = url.replace(/\/$/, ""); // 从URL中提取根域名 const rootDomain = this.getRootDomain(normalizedNewUrl); // 获取所有当前页面 const pages = await this.browser.pages(); // 尝试找到具有相同根域名的页面 let existingPage: Page | undefined; for (const page of pages) { try { const pageUrl = page.url(); if (pageUrl && this.getRootDomain(pageUrl) === rootDomain) { existingPage = page; break; } } catch (error) { // 跳过可能已关闭或有错误的页面 console.log(`检查页面URL时出错: ${error}`); continue; } } if (existingPage) { // 存在具有相同根域名的标签页,切换到它 console.log(`域名 ${rootDomain} 的标签页已存在,切换到它`); // 更新活动页面 this.page = existingPage; existingPage.bringToFront(); // 如果URL不同则导航到新URL const currentUrl = existingPage.url().replace(/\/$/, ""); // 如果存在,移除尾部/ if (this.getRootDomain(currentUrl) === rootDomain && currentUrl !== normalizedNewUrl) { console.log(`导航到新URL: ${normalizedNewUrl}`); // 导航到新URL return this.doAction(async (page) => { await this.navigatePageToUrl(page, normalizedNewUrl); }); } else { console.log(`域名 ${rootDomain} 的标签页已存在,且URL相同: ${normalizedNewUrl}`); // URL相同,只需重新加载页面以确保它是最新的 console.log(`重新加载页面: ${normalizedNewUrl}`); return this.doAction(async (page) => { await page.reload({ timeout: 15_000, waitUntil: ["domcontentloaded", "networkidle2"] }).catch(async (error) => { // 如果networkidle2失败,尝试仅等待domcontentloaded console.log(`重新加载网络静默等待失败,尝试仅等待DOM: ${error.message}`); await page.reload({ timeout: 15_000, waitUntil: ["domcontentloaded"] }); }); await this.waitTillHTMLStable(page); }); } } else { // 不存在此根域名的标签页,创建新的 console.log(`域名 ${rootDomain} 的标签页不存在,创建新的`); return this.createNewTab(normalizedNewUrl); } }
  • The input schema and metadata for the 'navigate_to' tool, defining it requires a 'url' string parameter.
    { name: "navigate_to", description: "导航到指定URL,智能管理标签页(相同域名复用标签页)", inputSchema: { type: "object", properties: { url: { type: "string", description: "要导航到的URL", }, }, required: ["url"], }, },
  • src/index.ts:182-187 (registration)
    Registration and dispatching logic in the CallToolRequestSchema handler: validates input and calls the browserSession.navigateToUrl method.
    case "navigate_to": if (!args?.url) { throw new Error("URL参数是必需的"); } result = await this.browserSession.navigateToUrl(args.url as string); break;
  • src/index.ts:44-164 (registration)
    Tool registration in ListToolsRequestSchema handler, where 'navigate_to' is listed among available tools with its schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "launch_browser", description: "启动浏览器连接,连接到Chrome调试端口以保持登录状态", inputSchema: { type: "object", properties: { remote_host: { type: "string", description: "可选的远程Chrome主机URL (例如: http://localhost:9222)", }, }, }, }, { name: "close_browser", description: "关闭浏览器连接", inputSchema: { type: "object", properties: {}, }, }, { name: "navigate_to", description: "导航到指定URL,智能管理标签页(相同域名复用标签页)", inputSchema: { type: "object", properties: { url: { type: "string", description: "要导航到的URL", }, }, required: ["url"], }, }, { name: "click", description: "在指定坐标位置点击", inputSchema: { type: "object", properties: { coordinate: { type: "string", description: "点击位置的坐标,格式为 'x,y'", }, }, required: ["coordinate"], }, }, { name: "type_text", description: "输入文本内容", inputSchema: { type: "object", properties: { text: { type: "string", description: "要输入的文本内容", }, }, required: ["text"], }, }, { name: "scroll_down", description: "向下滚动页面一个视口高度", inputSchema: { type: "object", properties: {}, }, }, { name: "scroll_up", description: "向上滚动页面一个视口高度", inputSchema: { type: "object", properties: {}, }, }, { name: "hover", description: "将鼠标悬停在指定坐标位置", inputSchema: { type: "object", properties: { coordinate: { type: "string", description: "悬停位置的坐标,格式为 'x,y'", }, }, required: ["coordinate"], }, }, { name: "resize_browser", description: "调整浏览器窗口大小", inputSchema: { type: "object", properties: { size: { type: "string", description: "窗口大小,格式为 'width,height'", }, }, required: ["size"], }, }, { name: "get_page_content", description: "获取当前页面的HTML内容", inputSchema: { type: "object", properties: {}, }, }, ] as Tool[], }; });

Latest Blog Posts

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/Rainmen-xia/chrome-debug-mcp'

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