fix: js -> ts

This commit is contained in:
hp0912 2026-06-02 23:55:34 +08:00
parent a3d0baa3d8
commit 37b1fd4010
5 changed files with 532 additions and 168 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
__pycache__ __pycache__
.venv .venv
node_modules
package-lock.json

View File

@ -12,7 +12,7 @@ argument-hint: "需要 urlmode 可为 content 或 screenshot自动化可
验证码处理采用安全边界内的自动检测:脚本可以识别常见验证码/人机验证页面并停止自动化,给出明确错误提示;不提供破解、绕过、代答验证码或规避网站风控的能力。遇到验证码时,应让用户在合法授权下人工完成验证,或使用已验证后的页面/会话环境继续处理。 验证码处理采用安全边界内的自动检测:脚本可以识别常见验证码/人机验证页面并停止自动化,给出明确错误提示;不提供破解、绕过、代答验证码或规避网站风控的能力。遇到验证码时,应让用户在合法授权下人工完成验证,或使用已验证后的页面/会话环境继续处理。
技能脚本位于 `scripts/web_page.js`,依赖基础镜像提供的 Node.js 24+ 和 Chromium。基础镜像中已配置 `CHROME_BIN=/usr/bin/chromium``CHROME_PATH=/usr/bin/chromium` 时,无需额外安装浏览器。 技能脚本位于 `scripts/web_page.ts`,依赖基础镜像提供的 Node.js 24+ 和全局安装的 `tsx`(用于直接运行 TypeScript以及 Chromium。基础镜像中已配置 `CHROME_BIN=/usr/bin/chromium``CHROME_PATH=/usr/bin/chromium` 时,无需额外安装浏览器。
## 触发条件 ## 触发条件
@ -146,7 +146,7 @@ argument-hint: "需要 urlmode 可为 content 或 screenshot自动化可
示例:点击链接后读取跳转页面内容。 示例:点击链接后读取跳转页面内容。
```bash ```bash
node scripts/web_page.js \ tsx scripts/web_page.ts \
--url 'https://example.com' \ --url 'https://example.com' \
--mode content \ --mode content \
--actions '[{"type":"click","text":"Learn more","wait_for_navigation":true}]' --actions '[{"type":"click","text":"Learn more","wait_for_navigation":true}]'
@ -155,7 +155,7 @@ node scripts/web_page.js \
示例:填写并提交表单。 示例:填写并提交表单。
```bash ```bash
node scripts/web_page.js \ tsx scripts/web_page.ts \
--url 'https://httpbin.org/forms/post' \ --url 'https://httpbin.org/forms/post' \
--mode content \ --mode content \
--actions '[{"type":"fill","selector":"input[name=custname]","value":"Alice"},{"type":"check","selector":"input[name=size]","index":2},{"type":"check","selector":"input[name=topping]","index":1},{"type":"click","text":"Submit order","wait_for_navigation":true}]' --actions '[{"type":"fill","selector":"input[name=custname]","value":"Alice"},{"type":"check","selector":"input[name=size]","index":2},{"type":"check","selector":"input[name=topping]","index":1},{"type":"click","text":"Submit order","wait_for_navigation":true}]'
@ -164,7 +164,7 @@ node scripts/web_page.js \
示例:交互后截图指定元素。 示例:交互后截图指定元素。
```bash ```bash
node scripts/web_page.js \ tsx scripts/web_page.ts \
--url 'https://example.com' \ --url 'https://example.com' \
--mode screenshot \ --mode screenshot \
--screenshot_mode selector \ --screenshot_mode selector \
@ -180,7 +180,7 @@ node scripts/web_page.js \
2. 在该技能目录执行脚本,例如: 2. 在该技能目录执行脚本,例如:
```bash ```bash
node scripts/web_page.js --url 'https://example.com' --mode content tsx scripts/web_page.ts --url 'https://example.com' --mode content
``` ```
3. 脚本会输出页面标题、最终 URL、meta 描述、主要标题、正文文本和主要链接。 3. 脚本会输出页面标题、最终 URL、meta 描述、主要标题、正文文本和主要链接。
@ -200,25 +200,25 @@ node scripts/web_page.js --url 'https://example.com' --mode content
2. 截整个页面: 2. 截整个页面:
```bash ```bash
node scripts/web_page.js --url 'https://example.com' --mode screenshot --screenshot_mode full tsx scripts/web_page.ts --url 'https://example.com' --mode screenshot --screenshot_mode full
``` ```
3. 截当前可视区域: 3. 截当前可视区域:
```bash ```bash
node scripts/web_page.js --url 'https://example.com' --mode screenshot --screenshot_mode viewport --width 1365 --height 900 tsx scripts/web_page.ts --url 'https://example.com' --mode screenshot --screenshot_mode viewport --width 1365 --height 900
``` ```
4. 截指定元素: 4. 截指定元素:
```bash ```bash
node scripts/web_page.js --url 'https://example.com' --mode screenshot --screenshot_mode selector --selector 'main' tsx scripts/web_page.ts --url 'https://example.com' --mode screenshot --screenshot_mode selector --selector 'main'
``` ```
5. 截指定页面区域: 5. 截指定页面区域:
```bash ```bash
node scripts/web_page.js --url 'https://example.com' --mode screenshot --screenshot_mode region --x 0 --y 300 --width 800 --height 600 tsx scripts/web_page.ts --url 'https://example.com' --mode screenshot --screenshot_mode region --x 0 --y 300 --width 800 --height 600
``` ```
6. 在机器人环境中,脚本默认会调用客户端接口 `POST http://127.0.0.1:{ROBOT_WECHAT_CLIENT_PORT}/api/v1/robot/message/send/image/local` 发送截图;如果缺少机器人环境变量,则只输出本地截图路径。 6. 在机器人环境中,脚本默认会调用客户端接口 `POST http://127.0.0.1:{ROBOT_WECHAT_CLIENT_PORT}/api/v1/robot/message/send/image/local` 发送截图;如果缺少机器人环境变量,则只输出本地截图路径。

View File

@ -0,0 +1,10 @@
{
"name": "web-page-skill",
"private": true,
"type": "module",
"devDependencies": {
"@types/node": "^25.9.1",
"tsx": "^4.22.4",
"typescript": "^6.0.3"
}
}

View File

@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "nodenext",
"moduleResolution": "nodenext",
"lib": ["ES2022", "DOM"],
"types": ["node"],
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
},
"include": ["*.ts"]
}

File diff suppressed because it is too large Load Diff