Chuyển đến nội dung
Skillpedia
Giao diện (UI/UX)40k · #7460

ui-screenshots

Skill này làm gì

Công cụ này “chụp ảnh” các trang web hoặc ứng dụng trong khi bạn đang phát triển chúng. Nó giúp bạn thấy giao diện đang thay đổi thế nào về mặt trực quan.

Khi nào nên dùng

  • ✓Để ghi lại giao diện một trang web trước khi thực hiện thay đổi.
  • ✓Để cho thấy các trạng thái cụ thể, như một menu hiện ra khi di chuột.
  • ✓Để chỉ chụp một phần màn hình mà không cần chụp lại toàn bộ.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/ui-screenshots/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/ui-screenshots/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Chụp ảnh màn hình trang web của tôi tại http://mysite.com”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ dùng chương trình có tên Playwright để “nhìn” trang web và chụp toàn bộ ảnh. Sau đó, nó dùng một công cụ khác (PIL) để cắt ảnh và chỉ hiển thị phần bạn muốn.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

UI Screenshots

Capture screenshots of web apps and graphical UIs during development to document visual changes.

When to Use This Skill

Use this skill when you need to:

  • Capture the current state of a running web app
  • Document a UI before and after a code change
  • Screenshot interactive states (tooltips, hovers, selected elements)
  • Capture specific sections of a page without re-screenshotting

Prerequisites

pip install playwright Pillow -q
playwright install chromium

Core Workflow

1. Take a raw full-page screenshot

from playwright.async_api import async_playwright

async def capture(url="http://localhost:3000", out="screenshot-raw.png", width=1400, height=5000):
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page(viewport={"width": width, "height": height})
        await page.goto(url, wait_until="networkidle")
        await page.wait_for_timeout(4000)  # let charts/animations render
        await page.screenshot(path=out, full_page=True)
        await browser.close()
  • Use a tall viewport (height=5000) so the page renders everything without scrolling
  • wait_until="networkidle" + wait_for_timeout(4000) ensures async charts load
  • full_page=True captures the entire scrollable content

2. View the raw image, then crop with PIL

Do NOT try to get perfect crops via Playwright's clip parameter. It's unreliable with full-page captures.

from PIL import Image

img = Image.open("screenshot-raw.png")
cropped = img.crop((left, top, right, bottom))  # adjust based on what you see
cropped.save("screenshot-final.png")
  1. Take the raw screenshot
  2. View it to see actual pixel positions
  3. Crop with PIL based on what you see
  4. View the result — if not right, re-crop (instant, no re-screenshot needed)

3. Iterate on crop, not on capture

  • Re-screenshotting is slow (browser launch + page load + render wait)
  • Re-cropping is instant (just PIL)
  • Get one good raw capture, then slice it as many ways as needed

4. Interactive states

element = page.locator("selector").first
await element.hover()
await page.wait_for_timeout(1000)  # let tooltip appear
await page.screenshot(path="screenshot-hover.png", full_page=True)

For "selected" state without hover effect, move the mouse away after clicking:

await element.click()
await page.mouse.move(300, 300)  # move away so hover doesn't show
await page.wait_for_timeout(500)
await page.screenshot(path="screenshot-selected.png", full_page=True)

5. Section-specific captures

Crop different sections from a single full-page screenshot:

img.crop((0, 200, 920, 900)).save("screenshot-header.png")
img.crop((0, 900, 920, 1600)).save("screenshot-main.png")

Guidelines

  1. Always capture before state BEFORE making any changes — if you forget, you have to revert code to get a before shot
  2. Before/after pairs must use the same viewport width and crop — otherwise the comparison is useless
  3. To get a "before" after you already changed code: use git checkout HEAD~1 -- <files> to revert, screenshot, then git checkout HEAD -- <files> to restore
  4. For interactive states: capture before AND after for each state — don't assume the "normal" before covers all cases
  5. Use device_scale_factor=1 in Playwright to force 1x pixels so screenshots match what users see at 100% zoom
  6. Charts need extra wait time — Plotly, D3, etc. render asynchronously; 4s minimum after networkidle
  7. Narrow viewport reveals rendering bugs — some border/alignment issues only appear at specific widths

Non-Web App Screenshots

For desktop apps (VS, WPF, WinForms, console apps, terminals) where Playwright can't reach.

mss + ctypes (recommended for desktop windows)

Find a window by title via Win32 API, capture its region with mss. Tested at ~33ms per capture.

import ctypes
from ctypes import c_int, Structure, byref, windll
import mss
from PIL import Image

user32 = windll.user32

def find_window(title_contains):
    """Find visible windows matching a title substring."""
    results = []
    WNDENUMPROC = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.c_void_p)
    def cb(hwnd, _):
        if user32.IsWindowVisible(hwnd):
            buf = ctypes.create_unicode_buffer(256)
            user32.GetWindowTextW(hwnd, buf, 256)

…
Câu hỏi thường gặp

Tôi có cần cài đặt gì không?

Có, bạn cần cài các công cụ “playwright” và “Pillow”, rồi tải các thành phần Playwright cho trình duyệt Chromium.

Vì sao không cắt ảnh trực tiếp trong Playwright?

Cắt trực tiếp trong Playwright có thể không chính xác, đặc biệt với toàn bộ trang. Dễ hơn là chụp ảnh đầy đủ rồi dùng PIL để cắt chính xác.

Nếu tôi muốn chụp ảnh ứng dụng không phải web, như VS Code thì sao?

Với ứng dụng máy tính, bạn có thể dùng cách khác với các thư viện “mss” và “ctypes” để tìm cửa sổ và chụp ảnh nó, miễn là cửa sổ đang hiển thị trên màn hình.

Chi tiết

Mô tả gốc của tác giả

Capture screenshots of web apps during development using Playwright and PIL. Supports full-page captures, interactive states, and an iterate-on-crop workflow that avoids slow re-screenshots.

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7460
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự