| name | browser-automation |
| version | 0.1.0 |
| author | devclaw |
| description | Browser automation with Playwright — navigate, click, fill forms, scrape |
| category | automation |
| tags | ["browser","playwright","automation","scraping","web"] |
| requires | {"bins":["npx","node"]} |
Browser Automation
Automate web browsers using Playwright for testing, scraping, and automation.
Setup
Node.js (required):
- macOS:
brew install node
- Ubuntu:
sudo apt install nodejs npm
Playwright (browsers):
npm install -g playwright
npx playwright install
Quick Scripts
npx playwright screenshot https://example.com screenshot.png
npx playwright pdf https://example.com page.pdf
Navigate & Screenshot
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png', fullPage: true });
await browser.close();
})();
node script.js
Click & Fill Forms
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://example.com/login');
await page.fill('#email', 'user@example.com');
await page.fill('#password', 'secretpassword');
await page.click('button[type="submit"]');
await page.waitForURL('**/dashboard');
await browser.close();
})();
Extract Data
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com/products');
const title = await page.textContent('h1');
const products = await page.$$eval('.product', items =>
items.map(item => ({
name: item.querySelector('.name')?.textContent,
price: item.querySelector('.price')?.textContent
}))
);
console.log(JSON.stringify(products, null, 2));
await browser.close();
})();
Handle Dialogs & Alerts
page.on('dialog', async dialog => {
console.log(dialog.message());
await dialog.accept();
});
Wait Strategies
await page.waitForSelector('.loaded');
await page.waitForSelector('text=Welcome');
await page.waitForLoadState('networkidle');
await page.waitForSelector('.element', { timeout: 5000 });
Authentication
const context = await browser.newContext();
await context.storageState({ path: 'auth.json' });
const context = await browser.newContext({ storageState: 'auth.json' });
Command Line
npx playwright test --project=chromium
npx playwright test --project=firefox
npx playwright test --project=webkit
npx playwright test --headed
npx playwright test --debug
npx playwright codegen https://example.com
Tips
- Use
headless: false to see browser during development
- Use
codegen to record actions and generate code
- Use
waitForLoadState('networkidle') for dynamic content
- Use
page.pause() for debugging
- Screenshots: PNG, JPEG supported
Triggers
browser automation, playwright, web scraping, automate browser,
click, fill form, screenshot, web testing