Skip to content

feat(ui-plugins): add Web Task Extension (web-task-extension) - #247

Open
ppppp2005-p wants to merge 13 commits into
zai-org:mainfrom
ppppp2005-p:feat/web-task-extension
Open

ppppp2005-p wants to merge 13 commits into
zai-org:mainfrom
ppppp2005-p:feat/web-task-extension

Conversation

@ppppp2005-p

Copy link
Copy Markdown

Plugin type (required) / 插件类型(必填)

  • UI Plugin / 是 UI 插件 — provides MCP Apps interactive pages / 提供 MCP Apps 交互页面
  • Standard plugin / 普通插件(非 UI)
  • Not applicable / 不适用

Affected plugin name(s) / 涉及的插件名称:web-task-extension (UI Plugin, new)

What / 改动内容

New community UI plugin Web Task Extension / 网页操作转浏览器扩展: a browser chore the user describes becomes steps and a Chrome / Edge Manifest V3 extension (Run-button popup, options page, minimal permissions with plain explanations). The extension is validated and zipped. Logging in is not automated.

Tools:

  • ext_new, ext_update (bumps the version), ext_check (re-validate the folder on disk), ext_list (read-only).
  • App-only: ext_state.

How it works:

  • Task model (src/task.ts, zod):
    • Steps:
      • open {url, newTab}, click {selector, text}, fill {selector, value, submit} (text, <select> by value or label, checkbox), wait {selector | ms, gone}.
      • extract {selector, fields, into, next, maxPages, limit}, with fields css, css@attr, @attr or ..
      • download {from, format csv|json, filename} | {selector, limit}.
    • Settings: text, number, date or select, used as {{key}}; built-ins {{today}} and {{now}}.
    • checkTask reports errors for unknown placeholders, placeholders in an Open URL's host, non-http URLs, a download before any extract, a wait with nothing to wait for, all-sites patterns and paths outside Downloads. It warns about password-like fills and about tasks that don't start with Open.
  • Permissions (permissions()):
    • storage + scripting; downloads only with a download step.
    • Host patterns from the Open URLs plus sites (scheme + host; ports and paths dropped). With no Open step, activeTab and no hosts.
    • Each permission has an English and Chinese reason, written to PERMISSIONS.md, the options page and the panel.
  • Generated extension (src/runtime/ext/, plain JS copied as-is; per-task data lives in task.json, never in code):
    • Service worker background.js:
      • Runs steps in a tab and waits for loads with tabs.onUpdated. Each page step is injected through chrome.scripting.executeScript with the self-contained pageStep from steps.js, which polls for elements with a timeout. React-safe value setter; input and change events.
      • Pagination follows next until it is missing. Column order comes from fields, because Chrome returns objects with sorted keys.
      • CSV gets a BOM, quoting and formula-injection guarding. Downloads use data URLs through chrome.downloads.
      • Progress and results go to chrome.storage.local. Friendly errors: no access to a site, not a web page, load timeout, missing settings.
    • Popup: Run, live step status, results preview, re-download.
    • Options page: settings, per-step timeout, steps, permission table.
    • Also: _locales/en and zh_CN, and generated PNG icons (rounded square with a play glyph, 4× supersampled, own PNG encoder).
  • Validation (validate(), 17 checks):
    • Manifest: JSON, MV3, name ≤ 75, description ≤ 132, version format; referenced files exist; icon PNG sizes.
    • Permissions: known; minimal (warning); exactly what the steps need; host patterns valid and covering every Open URL.
    • Code: MV3 CSP (no inline or remote scripts, inline handlers or javascript:); every script parses (vm.Script) with no eval or remote code; locales complete, including every message used.
    • Also size and task consistency.
    • A zip (fflate, fixed mtimes, without README / PERMISSIONS) is written only when there are no errors.

Panel:

  • Extension picker; Re-check; Edit steps (JSON → ext_update).
  • Result banner; steps with action badges; settings.
  • Permission table with reasons.
  • Static popup preview built from the extension's own CSS, icon and messages.
  • Checks list and load-in-Chrome instructions.

Network / API / side effects: none from the plugin, and no API keys. It writes extensions/<slug>/, extensions/<slug>-<version>.zip and .web-task-extension/extensions.json. No hooks. The generated extension makes no requests of its own.

Testing:

  • vitest (6 tests):
    • Permission derivation for the three sample tasks; match-pattern normalisation; task error and warning cases.
    • ext_new for the portal task: all 17 checks pass, manifest shape, icons, PERMISSIONS.md, exact zip contents; a duplicate is refused.
    • Bad task → bad_task with the reason. ext_update bumps 1.0.0 → 1.0.1 and drops downloads when the download step is removed.
    • ext_check after hand edits catches an inline script, an inline handler, a remote script, a syntax error, eval, a wrong icon size, tabs + <all_urls>, and writes no zip.
  • Chrome e2e (Chrome 156; the generated extensions are really loaded unpacked through CDP Extensions.loadUnpacked):
    • Panel: generate, edit steps → v1.0.1, an invalid edit is rejected, the English panel re-checks.
    • Options page: save the category.
    • Popup Run against a fictional local supplier portal: cookie banner, fill, select, checkbox, submit, delayed results, 2 pages. Result: 9 rows, harbor-parts/brakes-<date>.csv with the right columns and order, and 2 spec sheets downloaded.
    • Live run on books.toscrape.com: 32 books over 2 pages → JSON.
    • The activeTab extension explains that it needs a web page.

A ZCode Desktop demo recording is attached in the comments. / ZCode 桌面版演示录屏见评论。

Self-check / 自查清单

  • Plugin name is unique kebab-case; new external plugin directory is external_plugins/<name>/
  • Usage category is set (productivity)
  • Plugin type and affected names are declared above
  • version 0.1.0 in both plugin.json and marketplace.json
  • README.md (EN) and README_CN.md (中文) both provided and equivalent
  • description_i18n has both en and zh-CN
  • No secrets, machine-specific paths, or private dependencies
  • Model/API/network dependencies documented
  • python3 scripts/validate.py and python3 scripts/build_dist.py pass locally
  • Exercised in ZCode Desktop (ZCode 4.0.0, macOS arm64: installed from a local marketplace, asked it to build a browser extension that scrapes book titles and prices from books.toscrape.com with auto-paging and CSV export; the agent checked the page structure, then ext_new generated extensions/web-task/ plus a zip and the built-in check passed 17/17; demo video in the comments)

@ppppp2005-p

Copy link
Copy Markdown
Author

ZCode desktop demo (ZCode 4.0.0, macOS arm64)

web-task-extension-demo.mp4

Flow shown:

  1. Installed web-task-extension from a local marketplace built from this PR's branch.
  2. Asked ZCode to make a browser extension "图书价格采集": collect book titles and prices (columns title / price) from the list pages of https://books.toscrape.com/, follow the next-page link automatically, export the result as CSV, then run the check and report the output.
  3. The agent loaded the plugin's skill, fetched the page once to confirm the selectors (article.product_pod, full title from the h3 a title attribute, p.price_color, next page li.next a, 50 pages), then called ext_new with three steps (open → extract title/price with paging → download CSV).
  4. The plugin wrote the Manifest V3 extension to extensions/web-task/ and packed extensions/web-task-1.0.0.zip (16 KB). The check passed 17/17 with no warnings. The side panel shows the step list (OPEN / EXTRACT / DOWNLOAD), the minimal permissions (storage, scripting, downloads, https://books.toscrape.com/*) and the green check result. The extension was not loaded into a browser in this demo.

演示流程:本地 marketplace 安装 → 确认页面结构 → ext_new 生成扩展(打开 → 采集书名/价格并自动翻页 → 导出 CSV)→ 打包 zip,校验 17/17 通过;面板显示步骤和最小权限。

@panda920

Copy link
Copy Markdown
Collaborator

✅ Internal validation passed. A ZCode maintainer will review the change next; after acceptance, release checks run separately and this PR is closed automatically.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants