วิธีใช้ Claude Code สำหรับทำ Automation บน Browser

Ashley Innocent

Ashley Innocent

22 January 2026

วิธีใช้ Claude Code สำหรับทำ Automation บน Browser

การทำงานอัตโนมัติของเบราว์เซอร์เดิมทีต้องใช้การเขียนสคริปต์ที่ซับซ้อน การจัดการ Selector และการจัดการสถานะหน้าเว็บที่ไม่สามารถคาดเดาได้ Claude Code เปลี่ยนกระบวนการนี้โดยให้คุณอธิบายสิ่งที่คุณต้องการด้วยภาษาธรรมชาติ และให้ AI แปลเป็นการกระทำของเบราว์เซอร์ที่แม่นยำ

อะไรที่ทำให้การทำงานอัตโนมัติของเบราว์เซอร์ด้วย Claude Code มีประสิทธิภาพ:

💡
กำลังทดสอบ API ควบคู่ไปกับเวิร์กโฟลว์ของเบราว์เซอร์อยู่ใช่ไหม? Apidog เติมเต็มการทำงานอัตโนมัติของเบราว์เซอร์ด้วย Claude Code โดยการให้การทดสอบ API ด้วยภาพและ Mock Server เมื่อการทดสอบเบราว์เซอร์ของคุณเรียกใช้ API, Apidog จะช่วยคุณตรวจสอบวงจรการร้องขอ-ตอบกลับทั้งหมด ลองใช้ Apidog ฟรีเพื่อสร้างเวิร์กโฟลว์การทดสอบแบบ end-to-end ที่ครอบคลุม
ปุ่ม

คู่มือนี้ครอบคลุมทุกอย่างตั้งแต่การตั้งค่าพื้นฐานไปจนถึงรูปแบบการทำงานอัตโนมัติขั้นสูงโดยใช้เซิร์ฟเวอร์ MCP (Model Context Protocol)

ทำความเข้าใจตัวเลือกการทำงานอัตโนมัติของเบราว์เซอร์

Claude Code มีแนวทางหลายอย่างสำหรับการทำงานอัตโนมัติของเบราว์เซอร์ ซึ่งแต่ละอย่างเหมาะสมกับกรณีการใช้งานที่แตกต่างกัน

ตัวเลือกที่ 1: Playwright MCP (แนะนำ)

Playwright MCP ของ Microsoft เป็นแนวทางที่แนะนำสำหรับการทำงานอัตโนมัติของเบราว์เซอร์ด้วย Claude Code โดยมีข้อดีดังนี้:

ตัวเลือกที่ 2: Puppeteer MCP (ชุมชน)

แม้ว่าแพ็กเกจ Puppeteer MCP อย่างเป็นทางการจะถูกเลิกใช้งานแล้ว แต่ยังมีทางเลือกที่ดูแลโดยชุมชนอยู่:

ตัวเลือกที่ 3: Claude Computer Use API

สำหรับการควบคุมเดสก์ท็อปอย่างเต็มรูปแบบนอกเหนือจากเบราว์เซอร์:

ตารางเปรียบเทียบ

คุณสมบัติPlaywright MCPPuppeteer MCPComputer Use API
การรองรับเบราว์เซอร์Chromium, Firefox, WebKitChromium เท่านั้นเบราว์เซอร์ใดก็ได้
การบำรุงรักษาMicrosoft (เป็นทางการ)ชุมชนAnthropic
การกำหนดเป้าหมายองค์ประกอบแผนผังการเข้าถึงCSS selectorsภาพ/พิกัด
โหมด Headlessใช่ใช่ไม่ (ต้องแสดงผล)
เหมาะสำหรับการทดสอบเว็บ, การ Scrappingโปรเจกต์เก่าการทำงานอัตโนมัติของเดสก์ท็อป

การตั้งค่า Playwright MCP

Playwright MCP เป็นวิธีที่แนะนำในการเพิ่มการทำงานอัตโนมัติของเบราว์เซอร์ให้กับ Claude Code นี่คือวิธีการตั้งค่า

ข้อกำหนดเบื้องต้น

ขั้นตอนที่ 1: กำหนดค่า MCP Server

เพิ่ม Playwright MCP ในการตั้งค่า Claude Code ของคุณ สร้างหรือแก้ไข .claude/settings.json:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"],
      "env": {
        "PLAYWRIGHT_BROWSERS_PATH": "0"
      }
    }
  }
}

ขั้นตอนที่ 2: ตรวจสอบการติดตั้ง

เริ่ม Claude Code และตรวจสอบว่า MCP server ทำงานอยู่:

claude

คุณควรเห็น Playwright MCP อยู่ในรายการเครื่องมือที่ใช้งานได้ ทดสอบด้วยคำสั่งง่ายๆ:

Navigate to https://example.com and tell me the page title

ขั้นตอนที่ 3: กำหนดค่าตัวเลือกเบราว์เซอร์

สำหรับการควบคุมที่มากขึ้น ให้ปรับแต่งการตั้งค่า MCP server:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": [
        "@playwright/mcp@latest",
        "--browser", "chromium",
        "--headless"
      ],
      "env": {
        "PLAYWRIGHT_BROWSERS_PATH": "0"
      }
    }
  }
}

ตัวเลือกที่ใช้งานได้:

ขั้นตอนที่ 4: การรันใน CI/CD

สำหรับ Pipeline อัตโนมัติ ให้ใช้โหมด Headless:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": [
        "@playwright/mcp@latest",
        "--headless",
        "--browser", "chromium"
      ]
    }
  }
}

ทางเลือกอื่น: Puppeteer MCP

ถ้าคุณชอบ Puppeteer หรือมีเวิร์กโฟลว์ที่ใช้ Puppeteer อยู่แล้ว คุณสามารถใช้ MCP server ที่ดูแลโดยชุมชน

การติดตั้ง

ใช้ Puppeteer MCP server ของชุมชน:

{
  "mcpServers": {
    "puppeteer": {
      "command": "npx",
      "args": ["-y", "puppeteer-mcp-server"]
    }
  }
}

ทางเลือกอื่น: puppeteer-mcp-claude

อีกหนึ่งตัวเลือกของชุมชนที่มีการทำงานอัตโนมัติของเบราว์เซอร์ที่ครอบคลุม:

# Clone the repository
git clone https://github.com/jaenster/puppeteer-mcp-claude.git
cd puppeteer-mcp-claude
npm install

กำหนดค่าใน .claude/settings.json:

{
  "mcpServers": {
    "puppeteer": {
      "command": "node",
      "args": ["/path/to/puppeteer-mcp-claude/index.js"]
    }
  }
}

ความแตกต่างที่สำคัญจาก Playwright

แง่มุมPlaywright MCPPuppeteer MCP
การตั้งค่าnpx (ไม่ต้องติดตั้ง)อาจต้องติดตั้ง npm
เบราว์เซอร์หลากหลายChrome/Chromium
กลยุทธ์ Selectorแผนผังการเข้าถึงCSS/XPath
การบำรุงรักษาMicrosoftชุมชน

คำสั่งพื้นฐานสำหรับการทำงานอัตโนมัติของเบราว์เซอร์

เมื่อ MCP server ของคุณได้รับการกำหนดค่าแล้ว คุณสามารถควบคุมเบราว์เซอร์โดยใช้ภาษาธรรมชาติได้

การนำทาง

Navigate to https://github.com
Go to the login page on github.com
Open https://docs.example.com/api in a new tab

การโต้ตอบกับองค์ประกอบ

Click the "Sign In" button
Type "my-username" in the email field
Select "United States" from the country dropdown
Check the "Remember me" checkbox

การอ่านเนื้อหาหน้าเว็บ

Get the text content of the main heading
List all links on the current page
Extract the product prices from this page

การจับภาพหน้าจอ

Take a screenshot of the current page
Capture a screenshot of just the navigation menu

การรอและกำหนดเวลา

Wait for the loading spinner to disappear
Wait 3 seconds then click the submit button
Wait until the "Success" message appears

การจัดการฟอร์ม

Fill out the contact form:
- Name: John Doe
- Email: john@example.com
- Message: Testing automation
Then submit the form

การโต้ตอบที่ซับซ้อน

Scroll down to the footer and click the "Privacy Policy" link
Hover over the "Products" menu and click "Enterprise"
Drag the slider to the 75% position

รูปแบบการทำงานอัตโนมัติขั้นสูง

รูปแบบที่ 1: เวิร์กโฟลว์หลายขั้นตอน

สร้างลำดับการทำงานอัตโนมัติที่ซับซ้อน:

Automate the following checkout flow:
1. Navigate to https://shop.example.com
2. Search for "wireless headphones"
3. Click on the first product result
4. Select size "Medium" if available
5. Click "Add to Cart"
6. Go to cart and verify the item is there
7. Take a screenshot of the cart

รูปแบบที่ 2: การดึงข้อมูล

ดึงข้อมูลที่มีโครงสร้างจากหน้าเว็บ:

Go to https://news.ycombinator.com and extract the top 10 stories with:
- Title
- URL
- Points
- Number of comments
- Posted time ago

Format as JSON

รูปแบบที่ 3: เวิร์กโฟลว์การยืนยันตัวตน

จัดการลำดับการเข้าสู่ระบบ:

Log into the application:
1. Navigate to https://app.example.com/login
2. Enter username: test@example.com
3. Enter password from environment variable LOGIN_PASSWORD
4. Click Sign In
5. Wait for dashboard to load
6. Verify login succeeded by checking for "Welcome" text

รูปแบบที่ 4: การทดสอบ Visual Regression

เปรียบเทียบสถานะหน้าเว็บ:

1. Navigate to https://staging.example.com
2. Take a full-page screenshot named "staging-homepage"
3. Navigate to https://production.example.com
4. Take a full-page screenshot named "production-homepage"
5. Compare the two screenshots and report any differences

รูปแบบที่ 5: การตรวจสอบและการแจ้งเตือน

สร้างเวิร์กโฟลว์การตรวจสอบ:

Check if the service is healthy:
1. Navigate to https://status.example.com
2. Look for "All Systems Operational" text
3. If not found, extract the current status message
4. Take a screenshot for documentation
5. Report the findings

รูปแบบที่ 6: การทดสอบ E2E พร้อมการตรวจสอบ API

รวมการทดสอบเบราว์เซอร์และ API:

Test the user registration flow:
1. Navigate to https://app.example.com/register
2. Fill in registration form with test data
3. Submit the form
4. Wait for confirmation page
5. Verify the user was created by checking the API response
6. Take a screenshot of the success page

เมื่อทดสอบเวิร์กโฟลว์ที่เกี่ยวข้องกับ API ให้ใช้ Apidog เพื่อตรวจสอบการตอบกลับของ Backend คุณสามารถตรวจสอบได้ว่าการกระทำของเบราว์เซอร์ของคุณเรียกใช้ API ที่ถูกต้องและได้รับการตอบกลับที่คาดหวัง

กรณีการใช้งานจริง

กรณีใช้งาน 1: การจับภาพหน้าจอสำหรับการรีวิวโค้ดอัตโนมัติ

บันทึกเอกสารภาพสำหรับการรีวิวโค้ด:

For the PR review, capture screenshots of:
1. The login page before changes
2. The login page after changes
3. The error state when invalid credentials are entered
4. The success redirect after valid login

Save all screenshots to ./review-screenshots/

กรณีใช้งาน 2: การวิเคราะห์คู่แข่ง

ตรวจสอบเว็บไซต์คู่แข่ง:

Analyze competitor pricing:
1. Navigate to https://competitor.com/pricing
2. Extract all plan names and prices
3. Take a screenshot of the pricing page
4. Compare with our current pricing data
5. Generate a summary report

กรณีใช้งาน 3: การทดสอบฟอร์มอัตโนมัติ

ทดสอบการตรวจสอบฟอร์มในสถานการณ์ต่างๆ:

Test the contact form validation:

Test 1: Empty submission
- Submit empty form
- Verify all required field errors appear
- Screenshot: empty-form-errors.png

Test 2: Invalid email
- Enter "John" in name
- Enter "invalid-email" in email
- Submit
- Verify email validation error
- Screenshot: invalid-email-error.png

Test 3: Valid submission
- Fill all fields correctly
- Submit
- Verify success message
- Screenshot: form-success.png

กรณีใช้งาน 4: การตรวจสอบ SEO

ทำการตรวจสอบ SEO โดยอัตโนมัติ:

Perform SEO audit on https://mysite.com:
1. Check page title length (should be 50-60 characters)
2. Check meta description exists and length
3. Verify H1 tag exists and is unique
4. Check all images have alt text
5. Verify canonical URL is set
6. Check for broken links on the page
7. Generate audit report

กรณีใช้งาน 5: การทดสอบการเข้าถึง

ทำการตรวจสอบการเข้าถึงโดยอัตโนมัติ:

Run accessibility audit on https://app.example.com:
1. Navigate to the homepage
2. Check color contrast ratios
3. Verify all interactive elements are keyboard accessible
4. Check ARIA labels are present
5. Verify focus indicators are visible
6. Test with screen reader simulation
7. Generate accessibility report

กรณีใช้งาน 6: การตรวจสอบประสิทธิภาพ

ติดตามประสิทธิภาพการโหลดหน้าเว็บ:

Monitor page load performance:
1. Clear browser cache
2. Navigate to https://app.example.com
3. Record time to first contentful paint
4. Record time to interactive
5. Capture network waterfall
6. Take screenshot when fully loaded
7. Compare with baseline metrics

การรวมเข้ากับ CI/CD Pipeline

การรวม GitHub Actions

เพิ่มการทำงานอัตโนมัติของเบราว์เซอร์ใน CI Pipeline ของคุณ:

# .github/workflows/e2e-tests.yml
name: E2E Browser Tests

on:
  pull_request:
    branches: [main, develop]

jobs:
  browser-tests:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install Playwright Browsers
        run: npx playwright install --with-deps chromium

      - name: Install Claude Code
        run: npm install -g @anthropic-ai/claude-code

      - name: Run Browser Tests
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: |
          claude --mcp playwright "
            Run the following browser tests:
            1. Navigate to ${{ env.STAGING_URL }}
            2. Test login flow with test credentials
            3. Verify dashboard loads correctly
            4. Take screenshots of each step
            5. Report any failures
          "

      - name: Upload Screenshots
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: browser-test-screenshots
          path: screenshots/

การสร้างทักษะการทดสอบเบราว์เซอร์

สร้างทักษะที่นำกลับมาใช้ใหม่ได้สำหรับการทดสอบเบราว์เซอร์:

---
name: browser-test-runner
version: "1.0.0"
description: Runs browser-based E2E tests using Playwright MCP
user-invocable: true
allowed-tools:
  - Bash
  - Read
  - Write
  - mcp_playwright
---

# Browser Test Runner

Automated browser testing skill using Playwright MCP.

## Usage

```bash
/browser-test-runner --url https://app.example.com --suite smoke
/browser-test-runner --url https://staging.example.com --suite full

Claude Computer Use API

สำหรับสถานการณ์ที่ต้องการการควบคุมเดสก์ท็อปอย่างเต็มรูปแบบ Claude Computer Use API ของ Claude มีความสามารถในการทำงานอัตโนมัติที่ครอบคลุม

ภาพรวม

Computer Use เป็นฟีเจอร์เบต้าที่ช่วยให้ Claude สามารถ:

การตั้งค่าพื้นฐาน

import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    tools=[
        {
            "type": "computer_20250124",
            "name": "computer",
            "display_width_px": 1920,
            "display_height_px": 1080,
            "display_number": 1
        }
    ],
    messages=[
        {
            "role": "user",
            "content": "Open Chrome and navigate to github.com"
        }
    ],
    betas=["computer-use-2025-01-24"]
)

ควรใช้ Computer Use หรือ MCP เมื่อใด

สถานการณ์แนวทางที่แนะนำ
การ Scrapping เว็บPlaywright MCP
การทดสอบ E2EPlaywright MCP
การทำงานอัตโนมัติของแอปเดสก์ท็อปComputer Use API
เวิร์กโฟลว์ข้ามแอปพลิเคชันComputer Use API
CI/CD PipelinePlaywright MCP (headless)
การทดสอบด้วยภาพได้ทั้งสองอย่าง

แนวทางปฏิบัติที่ดีที่สุดสำหรับ Computer Use

  1. ตรวจสอบการกระทำเสมอก่อนคลิก
  2. ใช้พิกัดที่เฉพาะเจาะจงเมื่อเป็นไปได้
  3. เพิ่มการหน่วงเวลาระหว่างการกระทำที่รวดเร็ว
  4. ใช้การกู้คืนข้อผิดพลาดสำหรับการคลิกที่ไม่สำเร็จ
  5. จำกัดขอบเขตให้มีสิทธิ์ที่จำเป็นเท่านั้น

ข้อควรพิจารณาด้านความปลอดภัย

การจัดการการยืนยันตัวตน

ควรทำ:

ไม่ควรทำ:

# ใช้ตัวแปรสภาพแวดล้อม
export TEST_USERNAME="test@example.com"
export TEST_PASSWORD="secure-test-password"
Log in using credentials from environment variables
TEST_USERNAME and TEST_PASSWORD

ความเป็นส่วนตัวของข้อมูล

ควรทำ:

ไม่ควรทำ:

ความปลอดภัยของเครือข่าย

ควรทำ:

ไม่ควรทำ:

ความปลอดภัยของ MCP Server

  1. รันภายในเครื่องเมื่อเป็นไปได้
  2. ตรวจสอบโค้ด MCP serverก่อนใช้งาน
  3. จำกัดสิทธิ์ของเครื่องมือให้เหลือน้อยที่สุดเท่าที่จำเป็น
  4. ตรวจสอบบันทึก MCP serverเพื่อหาความผิดปกติ

สรุป

การทำงานอัตโนมัติของเบราว์เซอร์ด้วย Claude Code เปลี่ยนแปลงวิธีการที่นักพัฒนาใช้ในการทดสอบเว็บ, การ Scrapping และการทำงานอัตโนมัติ ด้วยการรวมคำสั่งภาษาธรรมชาติเข้ากับ MCP server ที่ทรงพลังอย่าง Playwright คุณสามารถสร้างเวิร์กโฟลว์การทำงานอัตโนมัติที่ซับซ้อนได้โดยไม่ต้องเขียนสคริปต์ที่ซับซ้อน

สำหรับการทดสอบที่ครอบคลุม ให้ใช้การทำงานอัตโนมัติของเบราว์เซอร์ด้วย Claude Code ควบคู่กับการตรวจสอบ API ดาวน์โหลด Apidog ฟรีเพื่อสร้างเวิร์กโฟลว์การทดสอบที่สมบูรณ์ซึ่งครอบคลุมทั้ง Frontend และ Backend ของคุณ

ปุ่ม

ฝึกการออกแบบ API แบบ Design-first ใน Apidog

ค้นพบวิธีที่ง่ายขึ้นในการสร้างและใช้ API

วิธีใช้ Claude Code สำหรับทำ Automation บน Browser