Use this file to discover all available pages before exploring further.
Notte sessions expose a Chrome DevTools Protocol (CDP) endpoint that you can connect to with Playwright. This allows you to use Playwright’s API directly while still benefiting from Notte’s cloud infrastructure, anti-detection features, and session management.
Get the CDP URL from a Notte session and connect Playwright to it:
from notte_sdk import NotteClientfrom playwright.sync_api import sync_playwrightclient = NotteClient()# Start a Notte sessionwith client.Session() as session: # Get CDP WebSocket URL cdp_url = session.cdp_url() print(f"CDP URL: {cdp_url}") # Connect Playwright to the Notte session with sync_playwright() as p: browser = p.chromium.connect_over_cdp(cdp_url) # Access the page (Notte sessions have one context with one page) context = browser.contexts[0] page = context.pages[0] # Use Playwright API directly page.goto("https://example.com") print(f"Title: {page.title()}") # Take a screenshot page.screenshot(path="screenshot.png")
Notte sessions automatically create a browser context with one page. Access it via browser.contexts[0].pages[0].
You can use both the Notte session API and Playwright simultaneously:
from notte_sdk import NotteClientfrom playwright.sync_api import sync_playwrightclient = NotteClient()with client.Session() as session: # Use Notte's built-in page notte_page = session.page notte_page.goto("https://example.com") # Also connect Playwright for advanced features cdp_url = session.cdp_url() with sync_playwright() as p: browser = p.chromium.connect_over_cdp(cdp_url) playwright_page = browser.contexts[0].pages[0] # Use Playwright's advanced features playwright_page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort()) # Navigate with route interception active playwright_page.goto("https://example.com/gallery") # Use Playwright's network monitoring with playwright_page.expect_response("**/api/data") as response_info: playwright_page.click("button#load-data") response = response_info.value print(f"API Response: {response.status()}")
Always use context managers for both Notte and Playwright to ensure proper cleanup:
playwright_context_managers.py
from notte_sdk import NotteClientfrom playwright.sync_api import sync_playwright # type: ignore[import-not-found]client = NotteClient()with client.Session() as session: with sync_playwright() as p: # Your code here pass
For simple automation, use session.page directly. Only connect Playwright when you need advanced features like network interception or custom contexts.