getPageUrl
Extract the current webpage URL during browser automation tasks with PlayMCP Server, enabling efficient web scraping, testing, and interaction workflows.
Instructions
Get the URL of the current page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:308-321 (handler)The core handler function in PlaywrightController that retrieves and returns the current browser page URL using Playwright API, with initialization check and error handling.async getPageUrl(): Promise<string> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Getting page URL'); const url = this.state.page?.url(); this.log('Page URL retrieved:', url); return url || ''; } catch (error: any) { console.error('Get page URL error:', error); throw new BrowserError('Failed to get page URL', 'Check if the page is loaded'); } }
- src/server.ts:113-121 (schema)MCP Tool definition including name, description, and input schema (no parameters required). This defines the tool's interface for the MCP protocol.const GET_PAGE_URL_TOOL: Tool = { name: "getPageUrl", description: "Get the URL of the current page", inputSchema: { type: "object", properties: {}, required: [] } };
- src/server.ts:514-553 (registration)Registration of the getPageUrl tool (via GET_PAGE_URL_TOOL) in the tools dictionary passed to MCP Server's capabilities, making it available for tool calls.const tools = { openBrowser: OPEN_BROWSER_TOOL, navigate: NAVIGATE_TOOL, type: TYPE_TOOL, click: CLICK_TOOL, moveMouse: MOVE_MOUSE_TOOL, scroll: SCROLL_TOOL, screenshot: SCREENSHOT_TOOL, getPageSource: GET_PAGE_SOURCE_TOOL, getPageText: GET_PAGE_TEXT_TOOL, getPageTitle: GET_PAGE_TITLE_TOOL, getPageUrl: GET_PAGE_URL_TOOL, getScripts: GET_SCRIPTS_TOOL, getStylesheets: GET_STYLESHEETS_TOOL, getMetaTags: GET_META_TAGS_TOOL, getLinks: GET_LINKS_TOOL, getImages: GET_IMAGES_TOOL, getForms: GET_FORMS_TOOL, getElementContent: GET_ELEMENT_CONTENT_TOOL, getElementHierarchy: GET_ELEMENT_HIERARCHY_TOOL, executeJavaScript: EXECUTE_JAVASCRIPT_TOOL, goForward: GO_FORWARD_TOOL, hover: HOVER_TOOL, dragAndDrop: DRAG_AND_DROP_TOOL, selectOption: SELECT_OPTION_TOOL, pressKey: PRESS_KEY_TOOL, waitForText: WAIT_FOR_TEXT_TOOL, waitForSelector: WAIT_FOR_SELECTOR_TOOL, resize: RESIZE_TOOL, handleDialog: HANDLE_DIALOG_TOOL, getConsoleMessages: GET_CONSOLE_MESSAGES_TOOL, getNetworkRequests: GET_NETWORK_REQUESTS_TOOL, uploadFiles: UPLOAD_FILES_TOOL, evaluateWithReturn: EVALUATE_WITH_RETURN_TOOL, takeScreenshot: TAKE_SCREENSHOT_TOOL, mouseMove: MOUSE_MOVE_TOOL, mouseClick: MOUSE_CLICK_TOOL, mouseDrag: MOUSE_DRAG_TOOL, closeBrowser: CLOSE_BROWSER_TOOL };
- src/server.ts:555-565 (registration)MCP Server instantiation with capabilities.tools (including getPageUrl), officially registering the toolset.const server = new Server( { name: "playmcp-browser", version: "1.0.0", }, { capabilities: { tools, }, } );
- src/server.ts:700-705 (handler)Dispatch handler in MCP callTool request handler that invokes the controller's getPageUrl method and formats the response for MCP protocol.case 'getPageUrl': { const url = await playwrightController.getPageUrl(); return { content: [{ type: "text", text: url }] }; }