Skip to content

Improve Chrome extension scan packaging and filtering#80

Closed
doggy8088 wants to merge 5 commits into
sysprog21:mainfrom
doggy8088:main
Closed

Improve Chrome extension scan packaging and filtering#80
doggy8088 wants to merge 5 commits into
sysprog21:mainfrom
doggy8088:main

Conversation

@doggy8088

@doggy8088 doggy8088 commented May 5, 2026

Copy link
Copy Markdown
Contributor

變更摘要

本 PR 針對 Chrome extension 的後續整理與修正,包含 WASM 建置/載入流程、Chrome extension package layout,以及 extension-only 的掃描結果過濾。這些變更主要集中在 extension/ 與 extension CI;其中 ...::: 忽略規則與 INFO 顯示過濾都只在瀏覽器 extension 層處理,不修改 Rust CLI / MCP server 的核心掃描邏輯。

Commit 範圍

本 PR 目前包含 4 個 commits:

  1. build(extension): optimize WASM build process and refactor loader
  2. Filter extension-only scan results
  3. build(extension): fix Chrome package layout
  4. build(extension): address review feedback

詳細變更紀錄

1. 改善 extension WASM 建置與載入流程

  • 調整 extension/build-wasm.sh,讓建置流程更適合 Chrome extension 使用。
  • 更新 extension/src/scanner.js 的 WASM 載入方式,透過 extension 內的 WASM glue 與 chrome.runtime.getURL() 取得 dist/zhtw_mcp_wasm_bg.wasm
  • 降低 extension 載入 WASM 時因路徑、打包結構或 glue code 初始化順序造成失敗的機率。

2. 修正 Chrome extension package layout

  • 更新 .github/workflows/extension-ci.yml,讓 CI 產出的 extension package 更符合 Chrome extension 載入需求。
  • 確保 package 內包含 extension 執行所需檔案,同時避免不必要或錯置的建置產物影響載入。

3. 新增 extension-only 掃描結果過濾

  • 在 extension 端新增 filterExtensionIgnoredIssues(),於 WASM 掃描結果回傳後、popup 顯示與 content highlight 前進行後處理。
  • 忽略常見頁面/文件 markup pattern:
    • ...
    • :::
  • 若 scanner 回報的是 pattern 內部的局部 issue,例如 ::: 內的單一 :,也會一併忽略。
  • 過濾後會重新計算:
    • issues
    • issue_count
    • badge_count
    • severity_counts

4. 隱藏沒有可見建議的 INFO 項目

  • 修正 popup 中出現空白 INFO 卡片的問題。
  • 部分 INFO issue 屬於刪除、插入或結構提示型訊息,WASM 可能回傳 suggestions: [""] 或空白字串;舊版 popup 只檢查 suggestions.length,因此會顯示 ai_style →punctuation → 這類沒有實質內容的項目。
  • 現在 extension 端會:
    • 清除空白 suggestion。
    • 隱藏 severity === "info" 且沒有任何可見建議的 issue。
    • 保留 warning / error,即使 suggestion 為空也不自動隱藏,避免漏掉較高嚴重性的結果。

5. 文件與測試

  • 更新 extension/README.md,說明 extension 有 browser-only result filtering,且不影響 Rust CLI / MCP server / WASM scanner 規則。
  • 擴充 extension/test/shared.test.js,覆蓋:
    • ... / ::: pattern 忽略。
    • pattern 範圍內局部 issue 忽略。
    • 無可見建議的 INFO issue 隱藏。
    • 過濾後 badge / severity 統計重算。

驗證

npm test --prefix extension

測試結果:6 tests passed。


Summary by cubic

Fixes MV3 service worker WASM loading by switching to static imports with explicit init, and adds browser-only filtering to hide ..., ::: noise and empty INFOs. Scan results are cleaner and the build/package is more reliable.

  • New Features

    • Ignore ... and ::: tokens and any issues in those ranges (extension-only).
    • Hide INFO issues without visible suggestions; keep warnings/errors. Recompute badge and severity counts.
  • Build/CI

    • Update build-wasm.sh: auto-provision wasm32-unknown-unknown via rustup; use a temp symlink PATH with cleanup; instruct cargo install wasm-pack.
    • Replace forbidden dynamic import() with a static top-level import in scanner.js for MV3 service worker; init WASM with chrome.runtime.getURL("dist/zhtw_mcp_wasm_bg.wasm").
    • Fix package layout and zip from the unpacked root; validate manifest.json and WASM assets in both the unpacked dir and the zip. Tests and README updated.

Written for commit 220f477. Summary will update on new commits.

Copilot AI review requested due to automatic review settings May 5, 2026 03:38
cubic-dev-ai[bot]

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Chrome extension’s WASM build/load and packaging flow, and adds extension-only post-processing to filter/hide certain scan results before UI rendering (without changing the core Rust/WASM scanner rules).

Changes:

  • Add extension-side filtering to ignore ... / ::: markup patterns (including issues that overlap those pattern ranges) and to hide INFO issues with no visible suggestions, while recomputing badge/severity counts.
  • Refactor WASM loading in the extension to use chrome.runtime.getURL() for the .wasm path and adjust packaging to zip the correct extension root layout, with CI validation.
  • Extend JS helper tests and update extension documentation to clarify browser-only filtering behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
extension/test/shared.test.js Adds tests for punctuation-pattern ignoring, in-pattern suppression, INFO hiding, and count recomputation.
extension/src/shared.js Implements extension-only issue filtering, INFO hiding/normalization, and severity recounting.
extension/src/scanner.js Updates WASM init/binding usage and applies extension-side filtering to scan results.
extension/README.md Documents that certain filters are extension-only and do not affect core scanner rules.
extension/build-wasm.sh Adjusts build environment setup (rustup target + PATH shims) for extension WASM builds.
.github/workflows/extension-ci.yml Fixes zip layout to package extension root correctly and validates required distributable files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/src/scanner.js
Comment thread extension/src/shared.js
Comment thread extension/build-wasm.sh
JackKuo-tw and others added 5 commits May 7, 2026 07:23
Dynamic import() is forbidden in ServiceWorkerGlobalScope by the HTML
spec. Since background.js runs as an MV3 service worker, the lazy
`await import("../dist/zhtw_mcp_wasm.js")` call in scanner.js caused
the WASM scanner to fail immediately with:

  import() is disallowed on ServiceWorkerGlobalScope by the HTML specification.

Replace it with a static top-level import (permitted in module service
workers declared with "type": "module") and pass the WASM URL directly
to the init function using the current object-parameter API.

Fixes: sysprog21#83

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tall

The rustwasm.github.io/wasm-pack/installer/ URL returns 404. The
alternative wasm-bindgen.github.io URL resolves but its shell installer
fails with "ORIG_ARGS[@]: unbound variable".

Since cargo is already required to build this project, direct users to
"cargo install wasm-pack" instead — consistent with the extension README.

Fixes: sysprog21#85

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@doggy8088

Copy link
Copy Markdown
Contributor Author

我這個 PR 三天沒有審核,另外兩個 PR 跟我這邊有點衝突,所以如果另外兩個合併後,我再重改一次好了,因此我先關閉

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.

3 participants