getPageUrl
Retrieve the current webpage URL to track navigation, verify page location, or extract web addresses during browser automation tasks.
Instructions
Get the URL of the current page
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:308-321 (handler)The handler function in PlaywrightController that retrieves and returns the current page URL using page.url(), with error handling for uninitialized browser.
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)The Tool object definition providing the schema for getPageUrl, including name, description, and empty input schema (no parameters required).
const GET_PAGE_URL_TOOL: Tool = { name: "getPageUrl", description: "Get the URL of the current page", inputSchema: { type: "object", properties: {}, required: [] } }; - src/server.ts:700-705 (registration)Registration in the callTool request handler switch statement that dispatches the getPageUrl tool call to the playwrightController.getPageUrl() method and returns the result.
case 'getPageUrl': { const url = await playwrightController.getPageUrl(); return { content: [{ type: "text", text: url }] }; } - src/server.ts:525-525 (registration)Registration of the getPageUrl tool in the tools dictionary used for capabilities and listTools.
getPageUrl: GET_PAGE_URL_TOOL,