Improve Chrome extension scan packaging and filtering#80
Closed
doggy8088 wants to merge 5 commits into
Closed
Conversation
There was a problem hiding this comment.
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.wasmpath 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.
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>
Contributor
Author
|
我這個 PR 三天沒有審核,另外兩個 PR 跟我這邊有點衝突,所以如果另外兩個合併後,我再重改一次好了,因此我先關閉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
變更摘要
本 PR 針對 Chrome extension 的後續整理與修正,包含 WASM 建置/載入流程、Chrome extension package layout,以及 extension-only 的掃描結果過濾。這些變更主要集中在
extension/與 extension CI;其中...、:::忽略規則與 INFO 顯示過濾都只在瀏覽器 extension 層處理,不修改 Rust CLI / MCP server 的核心掃描邏輯。Commit 範圍
本 PR 目前包含 4 個 commits:
build(extension): optimize WASM build process and refactor loaderFilter extension-only scan resultsbuild(extension): fix Chrome package layoutbuild(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。2. 修正 Chrome extension package layout
.github/workflows/extension-ci.yml,讓 CI 產出的 extension package 更符合 Chrome extension 載入需求。3. 新增 extension-only 掃描結果過濾
filterExtensionIgnoredIssues(),於 WASM 掃描結果回傳後、popup 顯示與 content highlight 前進行後處理。...::::::內的單一:,也會一併忽略。issuesissue_countbadge_countseverity_counts4. 隱藏沒有可見建議的 INFO 項目
suggestions: [""]或空白字串;舊版 popup 只檢查suggestions.length,因此會顯示ai_style →、punctuation →這類沒有實質內容的項目。severity === "info"且沒有任何可見建議的 issue。5. 文件與測試
extension/README.md,說明 extension 有 browser-only result filtering,且不影響 Rust CLI / MCP server / WASM scanner 規則。extension/test/shared.test.js,覆蓋:.../:::pattern 忽略。驗證
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
...and:::tokens and any issues in those ranges (extension-only).Build/CI
build-wasm.sh: auto-provisionwasm32-unknown-unknownviarustup; use a temp symlink PATH with cleanup; instructcargo install wasm-pack.import()with a static top-level import inscanner.jsfor MV3 service worker; init WASM withchrome.runtime.getURL("dist/zhtw_mcp_wasm_bg.wasm").manifest.jsonand WASM assets in both the unpacked dir and the zip. Tests and README updated.Written for commit 220f477. Summary will update on new commits.