Skip to content

Browser Automation

CodeBuddy integrates Playwright for headless browser automation, enabling tasks like testing web UIs, scraping data, filling forms, and taking screenshots. The browser tool wraps an MCP Playwright server with multiple security layers — SSRF prevention, input sanitization, JavaScript execution restrictions, and audit logging.

Browser automation requires Playwright with Chromium:

Terminal window
npx playwright install chromium
ActionParameterDescription
navigateurlOpen a URL in the browser
clickrefClick an element by accessibility reference
typeref, textType text into an input field
select_optionref, valueSelect an option from a dropdown
hoverrefHover over an element
press_keykeyPress a keyboard key
screenshotCapture the current page as an image
snapshotGet the accessibility tree (structured page content)
evaluateexpressionExecute JavaScript in the browser context
waittimeWait for a specified duration
tabNewurl?Open a new browser tab
tabCloseClose the current tab
tabSwitchSwitch between open tabs
tabListList all open tabs
goBackNavigate back in history
goForwardNavigate forward in history

The NavigationGuard prevents Server-Side Request Forgery by blocking navigation to internal networks:

  • Blocked addresses: RFC 1918 private ranges (10.x, 172.16-31.x, 192.168.x), loopback (127.x, ::1), link-local (169.254.x), IPv6 unique-local (fc00::/7)
  • Encoding detection: Catches octal, decimal, and hex IP obfuscation attempts
  • Post-navigation check: Verifies DNS resolution didn’t redirect to a private IP after the page loaded
  • Protocol restriction: Only http: and https: URLs are allowed
  • Length limits: Hostname ≤ 253 chars, pathname ≤ 2,048 chars, total URL ≤ 8,192 chars

The InputGuard validates all inputs before they reach the browser:

  • Element references: Maximum 512 characters, shell injection characters stripped
  • Key inputs: Must match ^[A-Za-z0-9+\-_]{1,64}$
  • No raw user input is passed to evaluate() without sanitization

The evaluate action blocks dangerous patterns:

  • fetch() and XMLHttpRequest — prevents data exfiltration
  • eval() and Function() — prevents arbitrary code execution
  • localStorage, sessionStorage, document.cookie — prevents credential theft
  • WebSocket — prevents covert channels
Open localhost:3000, take a screenshot of the login page, and check if the form is accessible
Navigate to our staging site, fill in the registration form with test data, and verify the success page
Open the dashboard, click the "Export" button, and verify the CSV download contains the expected columns
{
"codebuddy.browser.headless": true,
"codebuddy.browser.timeout": 30000,
"codebuddy.browser.viewport": { "width": 1280, "height": 720 }
}

Set headless to false to watch browser automation in real time.