.ipynb
.pdf
PlayWright Browser Toolkit
 Contents 
Instantiating a Browser Toolkit
Use within an Agent
PlayWright Browser Toolkit#
This toolkit is used to interact with the browser. While other tools (like the Requests tools) are fine for static sites, Browser toolkits let your agent navigate the web and interact with dynamically rendered sites. Some tools bundled within the Browser toolkit include:
NavigateTool (navigate_browser) - navigate to a URL
NavigateBackTool (previous_page) - wait for an element to appear
ClickTool (click_element) - click on an element (specified by selector)
ExtractTextTool (extract_text) - use beautiful soup to extract text from the current web page
ExtractHyperlinksTool (extract_hyperlinks) - use beautiful soup to extract hyperlinks from the current web page
GetElementsTool (get_elements) - select elements by CSS selector
CurrentPageTool (current_page) - get the current page URL
# !pip install playwright > /dev/null
# !pip install  lxml
# If this is your first time using playwright, you'll have to install a browser executable.
# Running `playwright install` by default installs a chromium browser executable.
# playwright install
from langchain.agents.agent_toolkits import PlayWrightBrowserToolkit
from langchain.tools.playwright.utils import (
    create_async_playwright_browser,
    create_sync_playwright_browser,# A synchronous browser is available, though it isn't compatible with jupyter.
)
# This import is required only for jupyter notebooks, since they have their own eventloop
import nest_asyncio
nest_asyncio.apply()
Instantiating a Browser Toolkit#
It’s always recommended to instantiate using the from_browser method so that the
async_browser = create_async_playwright_browser()
toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser)
tools = toolkit.get_tools()
rtdocs_stable/api.python.langchain.com/en/stable/modules/agents/toolkits/examples/playwright.html