scripts/puppeteer/README.md
This directory contains Puppeteer utilities designed to help AI agents (like Claude) test and debug the InfluxData documentation site during development.
Puppeteer enables AI agents to:
Due to network restrictions, install Puppeteer without downloading the browser binary:
PUPPETEER_SKIP_DOWNLOAD=true yarn install
If you're using system Chrome instead of Puppeteer's bundled browser, set the path in your scripts:
Common Chrome paths:
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome/usr/bin/google-chromeC:\Program Files\Google\Chrome\Application\chrome.exeYou can pass the Chrome path using the --chrome flag:
yarn debug:browser /influxdb3/core/ --chrome "/usr/bin/google-chrome"
Before using Puppeteer tools, make sure the Hugo development server is running:
npx hugo server
The server should be accessible at http://localhost:1313.
When a user reports an issue or you need to debug something:
Start Hugo server (if not already running)
npx hugo server
Inspect the page to gather information
yarn debug:inspect /influxdb3/core/get-started/
Take a screenshot to see visual issues
yarn debug:screenshot /influxdb3/core/get-started/ --full-page
Open browser interactively if you need to test manually
yarn debug:browser /influxdb3/core/get-started/ --devtools
yarn debug:inspect)Gather comprehensive information about a page:
yarn debug:inspect <url-path> [options]
What it reports:
data-component attributes)Examples:
# Inspect a page
yarn debug:inspect /influxdb3/core/
# Save report to JSON
yarn debug:inspect /influxdb3/core/ --output report.json
# Also capture a screenshot
yarn debug:inspect /influxdb3/core/ --screenshot
Use cases:
yarn debug:screenshot)Capture screenshots of pages or specific elements:
yarn debug:screenshot <url-path> [options]
Options:
--output PATH - Save to specific file--full-page - Capture entire scrollable page--selector CSS - Capture specific element--viewport WxH - Set viewport size (e.g., 375x667 for mobile)Examples:
# Basic screenshot
yarn debug:screenshot /influxdb3/core/
# Full page screenshot
yarn debug:screenshot /influxdb3/core/ --full-page
# Screenshot of specific element
yarn debug:screenshot /influxdb3/core/ --selector .article--content
# Mobile viewport screenshot
yarn debug:screenshot /influxdb3/core/ --viewport 375x667
# Custom output path
yarn debug:screenshot /influxdb3/core/ --output debug/home-page.png
Use cases:
yarn debug:browser)Launch a browser window for manual testing:
yarn debug:browser <url-path> [options]
Options:
--devtools - Open Chrome DevTools automatically--slow-mo NUM - Slow down actions by NUM milliseconds--viewport WxH - Set viewport size--base-url URL - Use different base URLExamples:
# Open page in browser
yarn debug:browser /influxdb3/core/
# Open with DevTools
yarn debug:browser /influxdb3/core/ --devtools
# Slow down for debugging
yarn debug:browser /influxdb3/core/ --slow-mo 500
# Mobile viewport
yarn debug:browser /influxdb3/core/ --viewport 375x667
Use cases:
AI agents can also use the helper functions directly in custom scripts:
import {
launchBrowser,
navigateToPage,
takeScreenshot,
getPageMetrics,
elementExists,
getElementText,
clickAndNavigate,
testComponent,
} from './utils/puppeteer-helpers.js';
// Launch browser
const browser = await launchBrowser({ headless: true });
// Navigate to page
const page = await navigateToPage(browser, '/influxdb3/core/');
// Check if element exists
const hasFormatSelector = await elementExists(page, '[data-component="format-selector"]');
console.log('Format selector present:', hasFormatSelector);
// Get text content
const title = await getElementText(page, 'h1');
console.log('Page title:', title);
// Take screenshot
await takeScreenshot(page, 'debug.png');
// Get performance metrics
const metrics = await getPageMetrics(page);
console.log('Load time:', metrics.performance.loadComplete);
// Close browser
await browser.close();
# Inspect the page for shortcode remnants
yarn debug:inspect /path/to/page/
# Take a screenshot to see the issue
yarn debug:screenshot /path/to/page/ --full-page --output shortcode-issue.png
What to look for in the report:
shortcodeRemnants section will show any {{< or {{% patterns# Inspect page for performance metrics
yarn debug:inspect /path/to/page/ --output performance-report.json
# Check the report for:
# - performance.performance.loadComplete (should be < 3000ms)
# - performance.performance.firstContentfulPaint (should be < 1500ms)
# Inspect page for console errors
yarn debug:inspect /path/to/page/
# Open browser with DevTools to see detailed error
yarn debug:browser /path/to/page/ --devtools
What to look for:
errors section in inspection report# Take screenshot at mobile viewport
yarn debug:screenshot /path/to/page/ --viewport 375x667 --output mobile-view.png
# Open browser at mobile viewport for testing
yarn debug:browser /path/to/page/ --viewport 375x667 --devtools
# 1. Inspect test page for components
yarn debug:inspect /example/ --screenshot
# 2. Take screenshots of different states
yarn debug:screenshot /example/ --selector '[data-component="tabs-wrapper"]'
# 3. Open browser to test interactivity
yarn debug:browser /example/ --devtools
// Create a custom script: test-responsive.js
import { launchBrowser, navigateToPage, takeScreenshot, testResponsive } from './utils/puppeteer-helpers.js';
const browser = await launchBrowser();
const page = await navigateToPage(browser, '/influxdb3/core/');
const viewports = [
{ width: 375, height: 667, name: 'iPhone SE' },
{ width: 768, height: 1024, name: 'iPad' },
{ width: 1280, height: 720, name: 'Desktop' },
{ width: 1920, height: 1080, name: 'Desktop HD' },
];
const results = await testResponsive(page, viewports, async (page, viewport) => {
await takeScreenshot(page, `responsive-${viewport.name}.png`);
const hasNav = await elementExists(page, '[data-component="mobile-nav"]');
return { hasNav };
});
console.log('Responsive test results:', results);
await browser.close();
node scripts/puppeteer/test-responsive.js
See utils/puppeteer-helpers.js for complete documentation. Key functions:
launchBrowser(options) - Launch browser instancenavigateToPage(browser, urlPath, options) - Navigate to pageclickAndNavigate(page, selector) - Click and wait for navigationelementExists(page, selector) - Check if element existswaitForElement(page, selector, timeout) - Wait for elementgetElementText(page, selector) - Get element text contentgetComputedStyles(page, selector, properties) - Get CSS stylestakeScreenshot(page, path, options) - Capture screenshotcompareScreenshots(baseline, current, diff) - Compare imagestestResponsive(page, viewports, testFn) - Test at different sizesgetPageMetrics(page) - Get performance metricsgetPageLinks(page) - Get all links on pagecaptureConsoleLogs(page) - Capture console outputdebugPage(page, name) - Save HTML + screenshot for debuggingtestComponent(page, selector, testFn) - Test component behaviorProblem: Puppeteer can't find Chrome executable
Solutions:
Use system Chrome:
yarn debug:browser /path/ --chrome "/usr/bin/google-chrome"
Install Puppeteer browser:
npx puppeteer browsers install chrome
Check common Chrome paths:
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome/usr/bin/google-chrome or /usr/bin/chromiumC:\Program Files\Google\Chrome\Application\chrome.exeProblem: Hugo server is not running
Solution:
# In a separate terminal
npx hugo server
Problem: Element doesn't exist on page or page hasn't finished loading
Solutions:
Wait for element:
await waitForElement(page, '.selector', 10000); // 10 second timeout
Check if element exists first:
if (await elementExists(page, '.selector')) {
// Element exists, safe to interact
}
Take screenshot to debug:
yarn debug:screenshot /path/ --output debug.png
Problem: Cannot download Puppeteer's bundled Chrome due to network restrictions
Solution:
# Install without browser binary
PUPPETEER_SKIP_DOWNLOAD=true yarn install
# Use system Chrome with --chrome flag
yarn debug:browser /path/ --chrome "/usr/bin/google-chrome"
# Check if server is responding
curl -s -o /dev/null -w "%{http_code}" http://localhost:1313/
If it returns 000 or connection refused, start Hugo:
npx hugo server
Inspection is faster and provides more context:
# First, inspect to understand the issue
yarn debug:inspect /path/
# Then take targeted screenshots if needed
yarn debug:screenshot /path/ --selector .problem-component
Headless mode is faster and doesn't require display:
const browser = await launchBrowser({ headless: true });
Only use non-headless (headless: false) when you need to visually debug.
Always close the browser when done:
try {
const browser = await launchBrowser();
const page = await navigateToPage(browser, '/path/');
// ... do work
} finally {
await browser.close();
}
# Bad
yarn debug:screenshot /path/ --output screenshot.png
# Good
yarn debug:screenshot /influxdb3/core/ --output debug/influxdb3-core-home-issue-123.png
When a user reports an issue, gather comprehensive context:
# 1. Inspection report
yarn debug:inspect /path/to/issue/ --output reports/issue-123-inspect.json --screenshot
# 2. Full page screenshot
yarn debug:screenshot /path/to/issue/ --full-page --output reports/issue-123-full.png
# 3. Element screenshot if specific
yarn debug:screenshot /path/to/issue/ --selector .problem-area --output reports/issue-123-element.png
# Before changes
yarn debug:screenshot /path/ --output before.png
# Make changes to code
# After changes (restart Hugo if needed)
yarn debug:screenshot /path/ --output after.png
# Compare visually
When developing a new component:
# 1. Open browser to test interactively
yarn debug:browser /example/ --devtools
# 2. Inspect for errors and components
yarn debug:inspect /example/
# 3. Take screenshots for documentation
yarn debug:screenshot /example/ --selector '[data-component="new-component"]'
# Create baseline screenshots
yarn debug:screenshot /influxdb3/core/ --output baselines/core-home.png
yarn debug:screenshot /influxdb3/core/get-started/ --output baselines/core-get-started.png
# After changes, compare
yarn debug:screenshot /influxdb3/core/ --output current/core-home.png
# Visual comparison (manual for now, can be automated with pixelmatch)
Install dependencies when you have network access:
PUPPETEER_SKIP_DOWNLOAD=true yarn install
Configure Chrome path if needed (see Troubleshooting)
Test the setup with a simple example:
npx hugo server # In one terminal
yarn debug:screenshot / # In another terminal
Start using for development - See Common Scenarios