Skip to main content
The get_url method retrieves the URL of the currently active page in the browser window. This is useful for verifying navigation, capturing the current state, or building conditional logic based on the page location.

Method Signature

async def get_url(
    self,
    *,
    timeout: int | None = None,
) -> GetUrlResponse

Parameters

timeout
int | None
default:"None"
Optional timeout in milliseconds. If not specified, uses the default timeout.

Return Value

Returns a GetUrlResponse object:
url
str
The URL of the currently active page.

Example

import asyncio

from narada import Agent, BrowserEnvironment

async def main():
    env = BrowserEnvironment()
    agent = Agent(environment=env)

    try:
        # Navigate to a page
        await agent.go_to_url(url="https://www.google.com", new_tab=True)

        # Get the current URL
        response = await agent.get_url()
        print(f"Current URL: {response.url}")
        # Output: Current URL: https://www.google.com/

        # Use in conditional logic
        await agent.run(prompt="Search for Narada AI")

        response = await agent.get_url()
        if "search" in response.url:
            print("Search results page loaded successfully")
    finally:
        await env.close()

if __name__ == "__main__":
    asyncio.run(main())

Use Cases

Verify Navigation

Confirm the browser navigated to the expected page after an action

Conditional Logic

Branch your automation based on the current page URL

Logging & Debugging

Log the current URL at each step for debugging automation flows

URL Extraction

Capture the final URL after redirects or form submissions