@bisonsoftware/canvas-grid-playwright

中文文档
0.3.0发布于 2025/10/08GPL-3.0-onlyTypeScriptESM + CJS零依赖近 30 天下载 4988

Canvas testing via grid overlay (Playwright-first).

原始使用文档
文档目录6 节
  1. Dependencies
  2. Note this whole library is still experimental.
  3. Basic Usage
  4. API Reference
  5. Core Methods
  6. Auto-Grid Sizing

Canvas Grid Library

A Playwright-first library for testing HTML5 Canvas elements using a grid-based approach.

Dependencies

This library requires Playwright as a peer dependency:

npm install @playwright/test

You must have Playwright installed in your project to use CanvasGrid.

Note this whole library is still experimental.

Basic Usage

import { test, expect } from '@playwright/test';
import {CanvasGrid} from "@bisonsoftware/canvas-grid-playwright";

test('canvas testing example', async ({ page }) => {
  await page.goto('https://your-canvas-app.com');
  
  // Create grid overlay
  const grid = new CanvasGrid(page)
    .locator('canvas')
    .gridSize(10, 8);  // 10 cols, 8 rows
  
  await grid.attach();
  
  // Interact with canvas
  await grid.clickCell(5, 4);
  await grid.hoverCell(3, 2);
});

API Reference

Core Methods

Setup

  • new CanvasGrid(page) - Initialize with Playwright page
  • .locator(selector) - Select canvas element(s)
  • .nth(index) - Select specific canvas when multiple match
  • .gridSize(cols, rows) - Set grid dimensions (optional, auto-sizes by default)
  • .attach() - Create and attach grid overlay

Mouse Interactions

  • .clickCell(col, row) - Left-click center of cell
  • .hoverCell(col, row) - Hover over center of cell
  • .doubleClickCell(col, row) - Double-click center of cell
  • .rightClickCell(col, row) - Right-click center of cell
  • .dragFromCellToCell(fromCol, fromRow, toCol, toRow) - Drag between cells

Tooltip Detection

  • .hoverCellAndCaptureTooltip(col, row, options?) - Hover and capture DOM tooltips
  • .waitForTooltip(options?) - Wait for tooltip to appear
  • .getVisibleTooltips(selectors?) - Get all currently visible tooltips
  • .scanAllCellsForTooltips(options?) - Scan entire grid for DOM tooltips
  • .hasAnyTooltips(options?) - Quick check if any DOM tooltips exist
  • .scanWithTextExtraction(options?) - Enhanced scan for DOM tooltips

Overlay Control

  • .interactive(boolean) - Enable/disable overlay mouse events
  • .toggleOverlay(boolean) - Show/hide overlay visibility

Auto-Grid Sizing

When no grid size is specified, the library automatically chooses based on canvas size:

  • Small canvas (< 400px): 6×4 grid
  • Medium canvas (400-900px): 10×8 grid
  • Large canvas (> 900px): 14×10 grid
// Auto-sizing based on canvas dimensions
const grid = new CanvasGrid(page).locator('#my-canvas');
await grid.attach(); // Grid size determined automatically

版本与发布记录

@bisonsoftware/canvas-grid-playwright 共发布 9 个版本,首次发布于 2025/10/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.0latest2025/10/081.1 年前
0.2.92025/10/061.1 年前
0.2.82025/10/051.1 年前
0.2.72025/10/041.1 年前
0.2.62025/10/041.1 年前
0.2.52025/10/041.1 年前

关于 @bisonsoftware/canvas-grid-playwright 的常见问题

@bisonsoftware/canvas-grid-playwright 是什么?

Canvas testing via grid overlay (Playwright-first).

如何安装 @bisonsoftware/canvas-grid-playwright?

在项目目录运行 npm install @bisonsoftware/canvas-grid-playwright,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@playwright/test(>=1.44.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bisonsoftware/canvas-grid-playwright 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bisonsoftware/canvas-grid-playwright 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bisonsoftware/canvas-grid-playwright 可以商用吗?

@bisonsoftware/canvas-grid-playwright 使用 GPL-3.0-only 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以 GPL-3.0 兼容许可开源,并附带专利与反锁定条款。仅内部使用不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@bisonsoftware/canvas-grid-playwright 的下载量有多少?

根据 npm 官方下载统计,@bisonsoftware/canvas-grid-playwright 在 2026/10/08 – 2026/11/06 这 30 天内被下载 4,988 次,日均约 166 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bisonsoftware/canvas-grid-playwright 还在维护吗?

最新版本 0.3.0 发布于 2025/10/08(1.1 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/10/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。