Improve Chrome extension scan packaging and filtering#79
Closed
doggy8088 wants to merge 3 commits into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a Chrome Manifest V3 extension packaging/CI pipeline and a browser-targeted WASM entrypoint, plus extension-only post-filtering of scan results so common markup punctuation noise doesn’t surface in the popup or page highlights.
Changes:
- Introduce a
browser-wasmbuild (with feature-gated Rust modules) and a WASM-exportedscan_text()API for the extension. - Add extension-side result filtering/hiding logic (ignored punctuation patterns + hide “info” issues with no visible suggestions) with Node tests.
- Add extension MV3 implementation (background/content/popup), styles, assets, and a CI workflow that builds and assembles a distributable zip.
Reviewed changes
Copilot reviewed 22 out of 31 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/wasm.rs |
Adds wasm-bindgen entrypoint and JSON serialization for browser scanning. |
src/rules/mod.rs |
Feature-gates native-only rules modules. |
src/rules/loader.rs |
Switches ruleset hash computation to use blake3 directly (removes native-only audit dependency). |
src/main.rs |
Refactors cfg(feature="translate") conditionals for cache/text retention logic. |
src/lib.rs |
Feature-gates native modules and exposes wasm module under browser-wasm. |
src/engine/scan/mod.rs |
Suppresses dead_code warnings for context helpers under browser-wasm. |
extension/test/shared.test.js |
Adds tests for extension-only filtering, hiding, and recomputed counters. |
extension/styles/popup.css |
Adds popup UI styling. |
extension/styles/content.css |
Adds page highlight styling for injected marks. |
extension/src/shared.js |
Adds shared helper functions (UTF-8 offset mapping, filtering/hiding, counters). |
extension/src/scanner.js |
Adds WASM loader + scan wrapper that applies extension-only filtering. |
extension/src/popup.js |
Adds popup UI logic to trigger scans and render results. |
extension/src/content.js |
Adds content script to collect visible text and apply highlights. |
extension/src/background.js |
Adds MV3 service worker orchestration, storage, badge updates, and highlighting. |
extension/scripts/generate-icons.sh |
Adds a script to generate icon PNGs from the SVG source. |
extension/README.md |
Documents building/loading/testing the extension and clarifies browser-only filtering. |
extension/popup.html |
Adds popup markup for controls and results list. |
extension/package.json |
Adds Node test script for extension helper tests. |
extension/manifest.json |
Adds MV3 manifest configuration, permissions, and CSP for WASM. |
extension/icons/source.svg |
Adds the source icon artwork. |
extension/build-wasm.sh |
Adds WASM build script for generating extension/dist/ outputs. |
Cargo.toml |
Introduces native/browser-wasm features, optional deps, and bin gating. |
Cargo.lock |
Updates lockfile for new optional WASM-related dependencies. |
.gitignore |
Ignores generated extension/dist/* outputs and a couple of repo artifacts. |
.github/workflows/extension-ci.yml |
Adds CI job to build WASM, test helpers, and assemble/upload extension artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+50
to
+67
| function filterExtensionIgnoredIssues(scanResult, text = "") { | ||
| const issues = Array.isArray(scanResult?.issues) ? scanResult.issues : []; | ||
| const ignoredRanges = ignoredPatternRanges(text); | ||
| const filteredIssues = issues | ||
| .map(normalizeDisplayIssue) | ||
| .filter( | ||
| (issue) => | ||
| !shouldIgnoreExtensionIssue(issue, ignoredRanges) && | ||
| !shouldHideExtensionIssue(issue), | ||
| ); | ||
|
|
||
| return { | ||
| ...scanResult, | ||
| issues: filteredIssues, | ||
| issue_count: filteredIssues.length, | ||
| badge_count: countBadgeIssues(filteredIssues), | ||
| severity_counts: countSeverityIssues(filteredIssues), | ||
| }; |
Comment on lines
+107
to
+123
| function ignoredPatternRanges(text) { | ||
| if (!text) { | ||
| return []; | ||
| } | ||
|
|
||
| const ranges = []; | ||
| for (const pattern of extensionIgnoredPatterns) { | ||
| let searchStart = 0; | ||
| while (searchStart < text.length) { | ||
| const index = text.indexOf(pattern, searchStart); | ||
| if (index < 0) { | ||
| break; | ||
| } | ||
| const byteStart = utf8ByteLength(text.slice(0, index)); | ||
| ranges.push({ | ||
| byteStart, | ||
| byteEnd: byteStart + utf8ByteLength(pattern), |
Comment on lines
+198
to
+208
| function issueToRanges(issue) { | ||
| if (!issue.length) { | ||
| return []; | ||
| } | ||
| const endByte = issue.offset + issue.length; | ||
| const startIndex = lastTextMap.findIndex( | ||
| (item) => issue.offset >= item.byteStart && issue.offset < item.byteEnd, | ||
| ); | ||
| const endIndex = lastTextMap.findIndex( | ||
| (item) => endByte > item.byteStart && endByte <= item.byteEnd, | ||
| ); |
- Add automatic `wasm32-unknown-unknown` target provisioning in `build-wasm.sh` using temporary symlink directory to ensure environment compatibility. - Register cleanup trap for temporary build artifacts. - Update `scanner.js` to use explicit WASM initialization imports for improved module loading consistency.
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 載入穩定性,以及只影響 extension UI 的掃描結果過濾。這些變更不調整 Rust CLI / MCP server 的核心掃描規則;新增的忽略與顯示邏輯都限制在
extension/的瀏覽器端結果處理。詳細變更紀錄
Chrome extension WASM 打包流程
extension/build-wasm.sh,讓 WASM 建置輸出更符合 Chrome extension 載入需求。extension/src/scanner.js的 WASM 載入流程,使用 extension 內的dist/zhtw_mcp_wasm_bg.wasm路徑,降低載入 glue code / wasm binary 時的路徑錯誤風險。Extension 專屬掃描結果過濾
filterExtensionIgnoredIssues(),在 WASM 掃描結果回傳到 popup / highlight 前進行 extension-only 後處理。...::::::內單一:,也會一併忽略,避免 popup 與頁面 highlight 出現雜訊。issuesissue_countbadge_countseverity_countsPopup INFO 顯示修正
suggestions: [""]或空白字串;原本 popup 只檢查suggestions.length,導致畫面顯示ai_style →、punctuation →這類沒有實質訊息的項目。severity === "info"且沒有任何可見建議的 issue。文件與測試
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
Adds a Chrome MV3 extension with stable WASM packaging/loading and browser-only result filtering to reduce UI noise. CLI/MCP scan rules are unchanged.
New Features
extension/build-wasm.shusingwasm-pack; loader resolvesdist/zhtw_mcp_wasm_bg.wasmviachrome.runtime.getURL.filterExtensionIgnoredIssues()to ignore...,:::and issues inside them; recomputeissues,issue_count,badge_count, andseverity_counts.wasm-bindgenentrypointscan_textbehind thebrowser-wasmfeature; includesrc/wasm.rs.npm test --prefix extension, assemble unpacked/zip artifacts, validate dist assets, and upload them.Bug Fixes
info, keepwarning/error.wasm32-unknown-unknowninbuild-wasm.sh, add a cleanup trap, and use explicit WASM init imports in the loader.manifest.jsonanddistassets in CI.Written for commit 834a1be. Summary will update on new commits.