@karinjs/plugin-puppeteer 1.1.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -0
- package/dist/{chunk-PIY2AHNK.js → chunk-TCCXNXHN.js} +19 -6
- package/dist/index.js +3 -4
- package/dist/web.config.js +1 -1
- package/package.json +18 -5
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @karinjs/plugin-puppeteer
|
|
2
|
+
|
|
3
|
+
[node-karin](https://github.com/KarinJS/Karin) 的 Puppeteer 截图/渲染插件,基于 [@snapka/puppeteer](https://www.npmjs.com/package/@snapka/puppeteer) 封装。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 自动下载/查找系统中的 Chrome 浏览器
|
|
8
|
+
- 支持 CDP 和 WebDriver BiDi 两种协议
|
|
9
|
+
- 页面池管理(复用 / 一次性模式)
|
|
10
|
+
- 并发截图队列与限速
|
|
11
|
+
- 提供 Web 管理面板(通过 node-karin Web UI 配置)
|
|
12
|
+
- 配置热更新
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
作为 [node-karin](https://github.com/KarinJS/Karin) 插件安装:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @karinjs/plugin-puppeteer -w
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 配置
|
|
23
|
+
|
|
24
|
+
插件首次运行时会自动生成默认配置文件,位于 `<karin数据目录>/@karinjs-plugin-puppeteer/config/config.json`。
|
|
25
|
+
|
|
26
|
+
也可以通过 node-karin 的 Web 管理面板修改配置。
|
|
27
|
+
|
|
28
|
+
### 配置项
|
|
29
|
+
|
|
30
|
+
| 配置项 | 类型 | 默认值 | 说明 |
|
|
31
|
+
|---|---|---|---|
|
|
32
|
+
| `protocol` | `'cdp' \| 'webDriverBiDi'` | `'cdp'` | 浏览器通信协议。CDP 稳定,BiDi 更快但仍在开发中 |
|
|
33
|
+
| `headless` | `'new' \| 'shell' \| false` | `'shell'` | 无头模式。`'new'` 新版无头、`'shell'` 传统无头(仅 chrome-headless-shell)、`false` 有头 |
|
|
34
|
+
| `debug` | `boolean` | `false` | 调试模式,浏览器前台运行且页面不自动关闭(仅 Windows) |
|
|
35
|
+
| `findBrowser` | `boolean` | `true` | 是否使用 @snapka/browser-finder 自动查找系统/puppeteer/playwright 已有的浏览器 |
|
|
36
|
+
| `pipe` | `boolean` | `false` | 是否使用管道模式与浏览器通信 |
|
|
37
|
+
| `slowMo` | `number` | `0` | 操作延迟(毫秒),用于调试 |
|
|
38
|
+
| `maxOpenPages` | `number` | `10` | 最大同时打开的标签页数量,超出排队 |
|
|
39
|
+
| `pageMode` | `'reuse' \| 'disposable'` | `'reuse'` | 页面模式。复用模式性能好,一次性模式隔离性强 |
|
|
40
|
+
| `pageIdleTimeout` | `number` | `60000` | 页面空闲超时时间(毫秒),`0` 表示永不超时 |
|
|
41
|
+
| `defaultViewport` | `{ width, height }` | `{ width: 800, height: 600 }` | 默认视窗大小 |
|
|
42
|
+
| `executablePath` | `string` | - | 浏览器可执行文件路径,为空则自动下载/查找 |
|
|
43
|
+
| `userDataDir` | `string` | - | 浏览器用户数据目录 |
|
|
44
|
+
| `args` | `string[]` | 见下方 | Chrome 启动参数 |
|
|
45
|
+
| `download.enable` | `boolean` | `true` | 是否启用浏览器自动下载 |
|
|
46
|
+
| `download.browser` | `'chrome' \| 'chromium' \| 'chrome-headless-shell'` | `'chrome-headless-shell'` | 下载的浏览器类型 |
|
|
47
|
+
| `download.version` | `string` | `'latest'` | 浏览器版本,支持 `latest`、`stable`、`beta`、`dev`、`canary` 或具体版本号 |
|
|
48
|
+
| `download.dir` | `string` | - | 下载目录,为空使用默认路径 |
|
|
49
|
+
| `download.baseUrl` | `string` | - | 自定义下载源 URL |
|
|
50
|
+
|
|
51
|
+
### 默认启动参数
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
--window-size=800,600
|
|
55
|
+
--disable-gpu
|
|
56
|
+
--no-sandbox
|
|
57
|
+
--disable-setuid-sandbox
|
|
58
|
+
--no-zygote
|
|
59
|
+
--disable-extensions
|
|
60
|
+
--disable-dev-shm-usage
|
|
61
|
+
--disable-background-networking
|
|
62
|
+
--disable-sync
|
|
63
|
+
--disable-crash-reporter
|
|
64
|
+
--disable-translate
|
|
65
|
+
--disable-notifications
|
|
66
|
+
--disable-device-discovery-notifications
|
|
67
|
+
--disable-accelerated-2d-canvas
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 开发
|
|
71
|
+
|
|
72
|
+
### 环境要求
|
|
73
|
+
|
|
74
|
+
- Node.js >= 18
|
|
75
|
+
- pnpm
|
|
76
|
+
|
|
77
|
+
### 目录结构
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
├── src/
|
|
81
|
+
│ ├── index.ts # 插件入口,注册渲染器
|
|
82
|
+
│ ├── app.ts # 开发模式入口
|
|
83
|
+
│ ├── web.config.ts # Web 管理面板配置
|
|
84
|
+
│ ├── utils.ts # 工具函数
|
|
85
|
+
│ ├── config/
|
|
86
|
+
│ │ └── index.ts # 配置管理
|
|
87
|
+
│ └── __mocks__/ # 测试 mock
|
|
88
|
+
├── tsconfig.json
|
|
89
|
+
├── tsup.config.ts
|
|
90
|
+
├── vitest.config.ts
|
|
91
|
+
├── eslint.config.mjs
|
|
92
|
+
└── package.json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 常用命令
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# 安装依赖
|
|
99
|
+
pnpm install
|
|
100
|
+
|
|
101
|
+
# 开发模式
|
|
102
|
+
pnpm dev
|
|
103
|
+
|
|
104
|
+
# 构建
|
|
105
|
+
pnpm build
|
|
106
|
+
|
|
107
|
+
# 运行测试
|
|
108
|
+
pnpm test
|
|
109
|
+
|
|
110
|
+
# 监听模式测试
|
|
111
|
+
pnpm test:watch
|
|
112
|
+
|
|
113
|
+
# 测试覆盖率
|
|
114
|
+
pnpm test:coverage
|
|
115
|
+
|
|
116
|
+
# Lint
|
|
117
|
+
pnpm lint
|
|
118
|
+
|
|
119
|
+
# 发布
|
|
120
|
+
pnpm pub
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 构建产物
|
|
124
|
+
|
|
125
|
+
构建输出到 `dist/` 目录,包含:
|
|
126
|
+
|
|
127
|
+
- `dist/index.js` - 插件入口
|
|
128
|
+
- `dist/web.config.js` - Web 管理面板配置
|
|
129
|
+
- `dist/*.d.ts` - 类型声明
|
|
130
|
+
|
|
131
|
+
## 协议
|
|
132
|
+
|
|
133
|
+
[MIT](LICENSE)
|
|
@@ -6,8 +6,8 @@ import { basePath } from 'node-karin/root';
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@karinjs/plugin-puppeteer",
|
|
9
|
-
version: "
|
|
10
|
-
description: "karin\u7684 puppeteer\u622A\u56FE\u3001\u6E32\u67D3\u63D2\u4EF6",
|
|
9
|
+
version: "2.0.1",
|
|
10
|
+
description: "karin \u7684 puppeteer \u622A\u56FE\u3001\u6E32\u67D3\u63D2\u4EF6",
|
|
11
11
|
keywords: [
|
|
12
12
|
"karin",
|
|
13
13
|
"node-karin",
|
|
@@ -24,19 +24,33 @@ var package_default = {
|
|
|
24
24
|
files: [
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
|
+
repository: {
|
|
28
|
+
type: "git",
|
|
29
|
+
url: "git+https://github.com/KarinJS/puppeteer.git"
|
|
30
|
+
},
|
|
27
31
|
scripts: {
|
|
28
32
|
build: "tsc && tsup",
|
|
29
33
|
dev: "tsx src/app.ts",
|
|
30
34
|
"dev:test": "node dist/index.js",
|
|
35
|
+
test: "vitest run",
|
|
36
|
+
"test:watch": "vitest",
|
|
37
|
+
"test:coverage": "vitest run --coverage",
|
|
31
38
|
pub: "pnpm publish --access public",
|
|
32
39
|
rm: `node -e "require('fs').rmSync('dist', { recursive: true, force: true })"`,
|
|
40
|
+
lint: "eslint src/",
|
|
33
41
|
sync: 'curl -X PUT "https://registry-direct.npmmirror.com/-/package/@karinjs/plugin-puppeteer/syncs"'
|
|
34
42
|
},
|
|
35
43
|
dependencies: {
|
|
36
|
-
"@snapka/puppeteer": "0.
|
|
44
|
+
"@snapka/puppeteer": "0.2.2"
|
|
37
45
|
},
|
|
38
46
|
devDependencies: {
|
|
39
|
-
"node
|
|
47
|
+
"@types/node": "^22.5.4",
|
|
48
|
+
eslint: "10.0.1",
|
|
49
|
+
neostandard: "0.12.2",
|
|
50
|
+
"node-karin": "^1.14.3",
|
|
51
|
+
tsup: "^8.5.1",
|
|
52
|
+
typescript: "5.9.3",
|
|
53
|
+
vitest: "^3.0.0"
|
|
40
54
|
},
|
|
41
55
|
karin: {
|
|
42
56
|
main: "src/index.ts",
|
|
@@ -46,8 +60,7 @@ var package_default = {
|
|
|
46
60
|
files: [
|
|
47
61
|
"config"
|
|
48
62
|
]
|
|
49
|
-
}
|
|
50
|
-
timestamp: "2025-10-01T00:47:22.222Z"
|
|
63
|
+
}
|
|
51
64
|
};
|
|
52
65
|
var HMR_KEY = "karin-plugin-puppeteer-hmr";
|
|
53
66
|
var defaultConfig = {
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { getConfig, HMR_KEY, pluginVersion, pluginName } from './chunk-
|
|
1
|
+
import { getConfig, HMR_KEY, pluginVersion, pluginName } from './chunk-TCCXNXHN.js';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { snapka } from '@snapka/puppeteer';
|
|
4
4
|
export * from '@snapka/puppeteer';
|
|
5
5
|
import { karin, registerRender, renderTpl, logger } from 'node-karin';
|
|
6
6
|
|
|
7
|
+
// src/utils.ts
|
|
7
8
|
var formatBytes = (bytes) => {
|
|
8
9
|
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
9
10
|
if (!bytes || bytes < 0) return "0 B";
|
|
@@ -45,9 +46,7 @@ var getScreenshotByteSize = (payload, encoding) => {
|
|
|
45
46
|
var main = async () => {
|
|
46
47
|
const config = getConfig();
|
|
47
48
|
const browser = await snapka.launch(config);
|
|
48
|
-
karin.on(HMR_KEY, async () =>
|
|
49
|
-
await browser.restart();
|
|
50
|
-
});
|
|
49
|
+
karin.on(HMR_KEY, async () => await browser.restart());
|
|
51
50
|
const name = "@karinjs/plugin-puppeteer";
|
|
52
51
|
registerRender(name, async (options) => {
|
|
53
52
|
options.encoding = "base64";
|
package/dist/web.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karinjs/plugin-puppeteer",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "karin的 puppeteer截图、渲染插件",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "karin 的 puppeteer 截图、渲染插件",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"karin",
|
|
7
7
|
"node-karin",
|
|
@@ -18,11 +18,21 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/KarinJS/puppeteer.git"
|
|
24
|
+
},
|
|
21
25
|
"dependencies": {
|
|
22
|
-
"@snapka/puppeteer": "0.
|
|
26
|
+
"@snapka/puppeteer": "0.2.2"
|
|
23
27
|
},
|
|
24
28
|
"devDependencies": {
|
|
25
|
-
"node
|
|
29
|
+
"@types/node": "^22.5.4",
|
|
30
|
+
"eslint": "10.0.1",
|
|
31
|
+
"neostandard": "0.12.2",
|
|
32
|
+
"node-karin": "^1.14.3",
|
|
33
|
+
"tsup": "^8.5.1",
|
|
34
|
+
"typescript": "5.9.3",
|
|
35
|
+
"vitest": "^3.0.0"
|
|
26
36
|
},
|
|
27
37
|
"karin": {
|
|
28
38
|
"main": "src/index.ts",
|
|
@@ -33,13 +43,16 @@
|
|
|
33
43
|
"config"
|
|
34
44
|
]
|
|
35
45
|
},
|
|
36
|
-
"timestamp": "2025-10-01T00:47:22.222Z",
|
|
37
46
|
"scripts": {
|
|
38
47
|
"build": "tsc && tsup",
|
|
39
48
|
"dev": "tsx src/app.ts",
|
|
40
49
|
"dev:test": "node dist/index.js",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"test:watch": "vitest",
|
|
52
|
+
"test:coverage": "vitest run --coverage",
|
|
41
53
|
"pub": "pnpm publish --access public",
|
|
42
54
|
"rm": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
55
|
+
"lint": "eslint src/",
|
|
43
56
|
"sync": "curl -X PUT \"https://registry-direct.npmmirror.com/-/package/@karinjs/plugin-puppeteer/syncs\""
|
|
44
57
|
}
|
|
45
58
|
}
|