skills/tools/playwright/SKILL.md
微软开发的跨浏览器自动化框架。使用单一API支持Chromium、Firefox和WebKit,用于测试、爬虫和自动化。
npx skillsauth add aidotnet/moyucode playwrightInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Cross-browser automation for testing, scraping, and web automation supporting Chromium, Firefox, and WebKit.
npm install playwright
npx playwright install # Install browsers
import { chromium, firefox, webkit } from 'playwright';
async function automateTask() {
// Launch any browser
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({
viewport: { width: 1920, height: 1080 },
userAgent: 'Custom User Agent',
});
const page = await context.newPage();
await page.goto('https://example.com');
// Click, type, interact
await page.click('button.login');
await page.fill('input[name="email"]', '[email protected]');
await page.fill('input[name="password"]', 'password123');
await page.click('button[type="submit"]');
// Wait for navigation
await page.waitForURL('**/dashboard');
await browser.close();
}
async function captureContent(url: string) {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(url);
// Screenshot
await page.screenshot({
path: 'screenshot.png',
fullPage: true,
});
// PDF (Chromium only)
await page.pdf({
path: 'document.pdf',
format: 'A4',
margin: { top: '1cm', bottom: '1cm' },
});
await browser.close();
}
async function scrapeProducts(url: string) {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(url);
// Use locators for reliable element selection
const products = await page.locator('.product-card').all();
const data = await Promise.all(products.map(async (product) => ({
name: await product.locator('.name').textContent(),
price: await product.locator('.price').textContent(),
rating: await product.locator('.rating').getAttribute('data-value'),
})));
await browser.close();
return data;
}
import { request } from 'playwright';
async function testAPI() {
const context = await request.newContext({
baseURL: 'https://api.example.com',
extraHTTPHeaders: {
'Authorization': 'Bearer token123',
},
});
// GET request
const response = await context.get('/users');
const users = await response.json();
// POST request
const createResponse = await context.post('/users', {
data: { name: 'John', email: '[email protected]' },
});
await context.dispose();
}
import { test, expect } from '@playwright/test';
test('user can login', async ({ page }) => {
await page.goto('/login');
await page.fill('[name="email"]', '[email protected]');
await page.fill('[name="password"]', 'password');
await page.click('button[type="submit"]');
await expect(page).toHaveURL('/dashboard');
await expect(page.locator('h1')).toHaveText('Welcome');
});
browser, testing, automation, e2e, scraping
development
使用Playwright浏览器爬取X(Twitter)真实数据,分析统计信息,生成精美的HTML报告面板并导出为高清图片。
development
使用CSS选择器从网页提取数据,支持分页、限速和多种输出格式。
tools
生成UUID(v1、v4、v5)和其他唯一标识符,如ULID、nanoid。
tools
使用各种服务缩短URL,并为短链接生成二维码。