feat: add Playwright support for browser automation in plugins

- Updated .dockerignore and .gitignore to exclude Playwright-related files.
- Added Playwright-Go dependency in go.mod and updated go.sum.
- Implemented jsPlaywright function in js_api.go for browser-based requests.
- Enhanced README.md to document the new Playwright functionality for plugins.
This commit is contained in:
krau
2025-11-07 11:07:47 +08:00
parent f0853536d9
commit f80ecae3cc
8 changed files with 165 additions and 9 deletions

View File

@@ -45,6 +45,7 @@ type Item struct {
- **registerParser**: 用于注册解析器, 每个插件必须调用此函数以注册
- **console.log**: 调用 go 端的 logger 打印日志
- **ghttp**: 提供 HTTP 请求功能
- **playwright**: 提供基于 Playwright 的浏览器自动化请求功能
插件需要提供元数据 `metadata` 并实现 `canHandle``parse` 两个函数, 最后调用 `registerParser` 注册解析器.
@@ -54,7 +55,7 @@ type Item struct {
```js
const metadata = {
version: "1.0.0", // 插件版本号, 必须提供, 其他字段可选
version: "1.0.0", // 插件兼容版本号, 必须提供, 其他字段可选
name: "Example Parser", // 插件名称
description: "A parser for example links", // 插件描述
author: "Krau", // 插件作者
@@ -142,6 +143,19 @@ if (response.status) {
}
```
#### Playwright
使用 `playwright` 对象以发起基于浏览器的请求.
**playwright.get(url: string)** 发起基于浏览器的 GET 请求, 当成功时返回响应体字符串, 失败时或响应状态码不为 200 时返回一个包含 `error` 字段的对象:
```js
const response = playwright.get("https://example.com/somepage");
if (response.error) {
console.log("Request failed:", response.error);
}
```
---
最后别忘了调用 `registerParser` 注册解析器: