AI agent instructions
AI agent instructions
Prerequisites
Install Puppeteer and the Notte SDK in your Node.js project:Use
puppeteer-core instead of puppeteer since you’re connecting to a remote browser rather than launching a local one.Approach 1: Start Session with the Node.js SDK
Start a Notte session with the Node.js SDK, get its CDP URL withsession.cdpUrl(), and connect Puppeteer. session.use() stops the session when the callback finishes:
Approach 2: Start Session from Python
Start a Notte session in Python and pass its CDP URL to a Node.js Puppeteer script:Approach 3: Connect with a Single URL
Passwss://api.notte.cc/sessions/connect?token=<NOTTE_API_KEY> as browserWSEndpoint to puppeteer.connect(). Connecting starts a new session, and browser.disconnect() or browser.close() stops it within a few seconds. See Connect with a Single URL for the supported query parameters and limits.
Network Interception
Use Puppeteer’s request interception with Notte sessions:Page Manipulation
Use Puppeteer’s API for advanced page interactions:Multiple Pages
Create and manage multiple pages with Puppeteer:Event Monitoring
Listen to browser events using Puppeteer:Handle JavaScript Dialogs
By default Notte answers JavaScript dialogs itself. To accept or dismiss them from Puppeteer, start the session withdialog_policy: 'client' and register page.on('dialog', dialog => dialog.accept()) before the page opens one. A dialog nobody answers within 10 seconds is dismissed. See Handle JavaScript dialogs for the full behavior.
Screenshots and PDFs
Generate screenshots and PDFs using Puppeteer:Best Practices
1. Use puppeteer-core
Always usepuppeteer-core instead of puppeteer since you’re connecting to a remote browser:
2. Handle Disconnections
CDP connections can be interrupted. Catch connection errors aroundpuppeteer.connect(). Put browser operations inside try/finally so errors still reach your session cleanup.
A connection can also drop before it is established, with socket hang up or ECONNRESET. Connecting again right away usually works, so retry such a failure once after a short delay, as the connect() helper in Approach 1 above does. Don’t retry an HTTP answer such as 403, 410 or 503 (Unexpected server response): connecting again gets the same answer.
3. Disconnect Properly
Callbrowser.disconnect() in finally to disconnect Puppeteer. For a session started with the SDK or the REST API, also stop the Notte session, or use session.use() to manage that lifecycle: disconnecting the client and stopping the session are separate operations. A session opened with a single URL stops when you disconnect.
4. Session Timeout
Remember that Notte sessions have a timeout. Set an appropriate value when creating the session:puppeteer_session_timeout.py
5. Environment Variables
Store your Notte API key in an environment variable: read the key fromprocess.env.NOTTE_API_KEY on your server. The complete example below shows the authenticated HTTP requests.
Complete Example: Web Scraping
Here’s a complete example that drives the REST API directly, without an SDK. Sessions are started withPOST /sessions/start and stopped with DELETE /sessions/{session_id}/stop:
When to Use Puppeteer with Notte
Use Puppeteer directly when you need:- Node.js ecosystem: Integrate with Node.js applications and packages
- Familiar Puppeteer API: You’re already comfortable with Puppeteer’s API
- Request interception: Block resources or modify requests
- Performance monitoring: Track page metrics and performance
- PDF generation: Create PDFs from web pages
Next Steps
Connect with Playwright
Use Playwright with Notte sessions
Migrating from Selenium
Port Selenium scripts to Playwright
External Browser Providers
Connect Notte to Kernel.sh and other providers
API Reference
Explore the Notte REST API