跳到正文
Skillpedia
网站与界面(前端)15k · #10922

node-lynx

它能做什么

为助手提供本地 Lynx 运行环境,用于渲染页面、截图和运行冒烟测试。适合构建或检查 Lynx 应用的开发者。

适用场景

  • ✓当你想在不打开设备的情况下,获得 Lynx 包的屏幕截图时。
  • ✓当你想在 Mac 的窗口中预览 Lynx 应用时。
  • ✓当你需要通过 Node.js 检查渲染后的 Lynx 页面的自动化流程时。

技能链接

https://github.com/lynx-family/lynx/blob/develop/oliver/node-lynx/skills/node-lynx/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/lynx-family/lynx/blob/develop/oliver/node-lynx/skills/node-lynx/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请以手机尺寸截取 gallery 示例 Lynx 应用的屏幕截图,并保存到一个文件中。”

每周 5 个新技能,1 分钟读完。

工作原理

助手会使用指定宽度、高度和输出路径运行 node-lynx 命令行工具。它也可以渲染本地包,或使用 JavaScript 接口进行更深入的检查。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Node Lynx

Use node-lynx as a local Lynx runtime for screenshots, preview windows, smoke tests, DebugRouter OpenCard sessions, and automation that needs to inspect or interact with a rendered Lynx page from Node.js.

Default sample template URL:

https://lynxjs.org/lynx-examples/gallery/dist/GalleryComplete.lynx.bundle

CLI

Prefer the CLI for one-off screenshots, quick template validation, and simple preview sessions.

Show available options:

node-lynx --help

Capture a headless screenshot and exit:

node-lynx render \
  "https://lynxjs.org/lynx-examples/gallery/dist/GalleryComplete.lynx.bundle" \
  --width 268 \
  --height 469 \
  --dpr 2 \
  --output ./gallery.png \
  --timeout 30000 \
  --screenshot-delay 500 \
  --no-debug-router

Render a local bundle:

node-lynx render \
  --template ./dist/main/template.js \
  --width 390 \
  --height 844 \
  --output ./node-lynx-local.png \
  --no-debug-router

Open a visible preview window on macOS:

node-lynx preview \
  "https://lynxjs.org/lynx-examples/gallery/dist/GalleryComplete.lynx.bundle" \
  --width 268 \
  --height 469 \
  --dpr 2 \
  --title "Node Lynx Preview"

Start a DebugRouter-backed session without an initial template:

node-lynx render

CLI rules:

  • Use render for headless screenshots and automation.
  • Use preview only on macOS; it creates an AppKit window.
  • Use --template <path> for local bundles and --url <url> for remote bundles. A positional http:// or https:// input is treated as a remote bundle URL.
  • Use --width and --height as CSS pixel viewport values.
  • Use --dpr or --device-pixel-ratio to control output scale; the PNG pixel size is width * dpr by height * dpr.
  • Use --timeout <ms> for bundle download, template load, CDP calls, and first frame submission timeouts.
  • Use --screenshot-delay <ms> to wait after the first frame before capture. This defaults to 100; use a larger delay for image-heavy or network-heavy pages.
  • Pass --no-debug-router for CI or one-shot screenshot commands that should exit immediately after writing the PNG.
  • Omit --no-debug-router when you need DebugRouter/OpenCard. Without an initial template, render waits for DebugRouter OpenCard. preview also waits for OpenCard without creating an initial window.
  • OpenCard only loads public http(s) URLs by default. Pass --allow-any-open-card-source (API: allowAnySource: true) to load local files or a loopback/private dev server, only on a trusted network.

TypeScript API

Prefer the API when the task needs programmatic setup, repeated captures, global props, CDP calls, input simulation, or custom lifecycle handling.

Import from the node-lynx package declared by the target project. For public npm usage this is typically:

import { HeadlessLynxView } from '@lynx-js/node-lynx';

Render a remote template to PNG:

import { writeFile } from 'node:fs/promises';
import { HeadlessLynxView } from '@lynx-js/node-lynx';

const templateUrl =
  'https://lynxjs.org/lynx-examples/gallery/dist/GalleryComplete.lynx.bundle';

const view = new HeadlessLynxView({
  width: 268,
  height: 469,
  devicePixelRatio: 2,
  timeoutMs: 30000,
});

try {
  await view.loadTemplateFromUrl(templateUrl, {
    initialData: { source: 'node-lynx' },
    globalProps: { theme: 'light' },
  });
  const png = await view.screenshot({ settleMs: 500 });
  await writeFile('./gallery.png', png);
} finally {
  view.destroy();
}

Render a local bundle buffer. Always pass a file URL so relative resources have the right base URL:

import { readFile, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import { HeadlessLynxView } from '@lynx-js/node-lynx';

const templatePath = resolve('./dist/main/template.js');
const view = new HeadlessLynxView({ width: 390, height: 844 });

try {
  await view.loadTemplate(await readFile(templatePath), {
    url: pathToFileURL(templatePath).href,
  });
  await writeFile('./node-lynx-local.png', await view.screenshot());
} finally {
  view.destroy();
}

Inspect the DOM through CDP:

const responseText = await view.invokeCDPFromSDK(
  JSON.stringify({
    id: 1,
    method: 'DOM.getDocument',
    params: { depth: -1, pierce: true },
  })
);
const response = JSON.parse(responseText);

Update runtime data after load:

view.updateData({ selected: true 
常见问题

使用它需要 Mac 吗?

截图不需要,截图以无界面方式运行。预览窗口仅在 macOS 上可用。

它能渲染本地应用吗?

可以。它既可以加载本地模板文件,也可以加载网络上的包链接。

默认示例显示什么?

默认会从 Lynx 示例网站加载一个 Lynx gallery 示例包。

详情

作者的原始描述

Use this skill when a task needs to run Lynx bundles with the node-lynx CLI, capture screenshots, open a macOS preview window, use DebugRouter OpenCard, inspect rendered content through CDP, or integrate node-lynx through JavaScript or TypeScript APIs.

repo: lynx-family/lynx

热度

GitHub 星标
15k
排名
#10922
许可证
Apache-2.0
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能