Skip to main content
The environment close method gracefully closes the current browser environment. For local browser environments, you can also access the browser process ID and terminate the entire browser application.

Method Signature

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

Parameters

timeout
int | None
default:"None"
Maximum time in seconds to wait for the environment to close. If None, uses the default system timeout.
timeout=5      # Wait up to 5 seconds
timeout=None   # Use default timeout

Return Value

This method returns None and completes when the environment has been closed.

Example

import asyncio

from narada import Agent, BrowserEnvironment

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

    try:
        # Perform automation tasks
        response = await agent.run(
            prompt="Search for Python tutorials and open the first result"
        )

        print(f"Task completed: {response.text}")
    finally:
        # Close this specific browser environment
        await env.close()


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