Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
245 commits
Select commit Hold shift + click to select a range
c0444dc
🔒 harden MAIN-world GM RPC capability binding
cyfung1031 Sep 16, 2026
a6e69ed
🐛 allow async GM XHR page RPC alias
cyfung1031 Sep 16, 2026
ef945e8
🔒 harden userscript invocation against page substitution
cyfung1031 Sep 16, 2026
1eb1839
🔒 isolate USER_SCRIPT GM transport and binding rotation
cyfung1031 Sep 17, 2026
3037623
🐛 route USER_SCRIPT GM calls to service worker
cyfung1031 Sep 17, 2026
25714ff
🧹 format USER_SCRIPT transport regression test
cyfung1031 Sep 17, 2026
a46b042
🔒 harden page and USER_SCRIPT execution bindings
cyfung1031 Sep 17, 2026
d65bcf3
🔒 secure USER_SCRIPT bootstrap and page capability checks
cyfung1031 Sep 17, 2026
e1ccf07
🐛 preserve GM API registry enumeration
cyfung1031 Sep 17, 2026
9f98995
🐛 make GM API registry merge-compatible
cyfung1031 Sep 17, 2026
9868594
⚡ reduce native reflection overhead
cyfung1031 Sep 17, 2026
f49053a
⚡ reduce content callback overhead
cyfung1031 Sep 17, 2026
d56b7a8
Merge remote-tracking branch 'origin/main' into codex/main-world-secu…
cyfung1031 Sep 17, 2026
47c2704
⚡ avoid receiver binding for pure agent APIs
cyfung1031 Sep 17, 2026
8bcad36
⚡ capture native collection methods on subclasses
cyfung1031 Sep 17, 2026
f2aad91
⚡ remove GM API receiver binding
cyfung1031 Sep 17, 2026
f13f7e2
⚡️ reduce runtime function overhead
cyfung1031 Sep 18, 2026
edc3ab3
⚡️ remove redundant native collection factories
cyfung1031 Sep 18, 2026
b5007df
⚡️ simplify native set initialization
cyfung1031 Sep 18, 2026
4d194e1
📄 补充跨世界安全边界维护注释
cyfung1031 Sep 18, 2026
9d0de58
🔒 separate asynchronous page RPC transport
cyfung1031 Sep 18, 2026
3448728
🔒 hide GM broker state behind script facade
cyfung1031 Sep 18, 2026
6a014bf
🔒 reject executable values at GM clone boundaries
cyfung1031 Sep 18, 2026
eb66888
🐛 settle GM XHR aborts without callbacks
cyfung1031 Sep 18, 2026
1d0dd85
🐛 continue page script loading after early reconciliation
cyfung1031 Sep 18, 2026
7780934
🔒 clone DOM bridge payloads before validation
cyfung1031 Sep 18, 2026
2993bbc
🔒 validate Blob page RPC payloads
cyfung1031 Sep 18, 2026
9c0650d
🔒 reject executable GM values
cyfung1031 Sep 18, 2026
398c884
🔒 reject non-cloneable GM values
cyfung1031 Sep 18, 2026
06bbf29
🔒 harden page RPC intrinsic boundaries
cyfung1031 Sep 18, 2026
4a4a127
🐛 preserve zero-valued tab identities
cyfung1031 Sep 18, 2026
a5a9b84
🐛 delete falsy GM values consistently
cyfung1031 Sep 18, 2026
340fea9
🔒 avoid accessor execution in GM_setValues
cyfung1031 Sep 18, 2026
884642a
🔒 preserve none grant capability boundary
cyfung1031 Sep 18, 2026
3d45436
🔒 capture grant alias intrinsics
cyfung1031 Sep 18, 2026
764a550
🔒 isolate grant capability map lookups
cyfung1031 Sep 18, 2026
525b2ed
🔒 harden capability collection construction
cyfung1031 Sep 18, 2026
c37446a
🔒 seal page RPC collection iteration
cyfung1031 Sep 18, 2026
18255a0
🐛 honor early GM XHR aborts
cyfung1031 Sep 18, 2026
ad61560
🐛 settle GM XHR connection failures
cyfung1031 Sep 18, 2026
68f4d3c
🐛 settle GM XHR setup errors
cyfung1031 Sep 18, 2026
f4edd72
🔒 discard stale page load bindings
cyfung1031 Sep 18, 2026
842d5ee
🔒 harden GM value transport collection writes
cyfung1031 Sep 18, 2026
fa26a1b
🔒 bind page execution handles to navigation URL
cyfung1031 Sep 18, 2026
86193c0
🔒 hide CAT conversation state behind private fields
cyfung1031 Sep 18, 2026
0bc23a6
🔒 close GM XHR connections on setup failure
cyfung1031 Sep 18, 2026
35b6766
🔒 avoid accessor execution in GM DOM attributes
cyfung1031 Sep 18, 2026
cb49bf8
🔒 copy GM menu options without accessors
cyfung1031 Sep 18, 2026
ef3adf5
🔒 copy GM XHR headers without accessors
cyfung1031 Sep 18, 2026
5acba1b
🔒 copy GM tab options without accessors
cyfung1031 Sep 18, 2026
13d6645
🔒 copy notification details without accessors
cyfung1031 Sep 18, 2026
6bf76fd
⚡️ reduce USER_SCRIPT callback dispatch scans
cyfung1031 Sep 18, 2026
714008e
🔒 prune revoked USER_SCRIPT connections
cyfung1031 Sep 18, 2026
63b01b3
🔒 harden USER_SCRIPT reconnect sessions
cyfung1031 Sep 18, 2026
3a8c561
🔒 validate inject page bootstrap DTOs
cyfung1031 Sep 18, 2026
cf9ee7b
🔒 validate inject runtime callback DTOs
cyfung1031 Sep 18, 2026
d2b2d84
🔒 avoid duplicate USER_SCRIPT bootstrap execution
cyfung1031 Sep 18, 2026
a64a1cb
🔒 route MAIN privileged traffic over native channel
cyfung1031 Sep 18, 2026
281e449
🔒 redact early-start preload values
cyfung1031 Sep 18, 2026
50a08b2
🔒 settle XHR errors without broker loadend
cyfung1031 Sep 18, 2026
b84ccaf
🔒 isolate protected GM facade keys
cyfung1031 Sep 18, 2026
cfb698c
🔒 keep service worker bridge bundle DOM-free
cyfung1031 Sep 18, 2026
8df243d
🔒 validate USER_SCRIPT bridge DTOs
cyfung1031 Sep 18, 2026
beb742c
🔒 bind CAT tasks to script owners
cyfung1031 Sep 18, 2026
e2738c9
🔒 bind CAT conversations to script owners
cyfung1031 Sep 18, 2026
283edd2
🔒 bind USER_SCRIPT tokens to page URLs
cyfung1031 Sep 18, 2026
c8516c9
🔒 bind early-start metadata to injected wrappers
cyfung1031 Sep 18, 2026
20d39af
🔒 restore early-start manifest execution
cyfung1031 Sep 18, 2026
3372fbe
🔒 retire stale page bindings on navigation
cyfung1031 Sep 18, 2026
f371261
🔒 bind CAT agent service identities
cyfung1031 Sep 18, 2026
3ab6b2d
🔒 target private callbacks to frame zero
cyfung1031 Sep 18, 2026
2f5b1fb
🔒 bind DOM monitors to script owners
cyfung1031 Sep 18, 2026
1f769a6
🔒 gate MAIN page bootstrap transport
cyfung1031 Sep 18, 2026
2f8dcd6
🔒 preserve USER_SCRIPT native fallback
cyfung1031 Sep 18, 2026
901016d
🔒 queue USER_SCRIPT value updates across reconnects
cyfung1031 Sep 18, 2026
643af56
🔒 protect GM value stores from prototype keys
cyfung1031 Sep 18, 2026
8f4cf28
🔒 reject hostile page message envelopes
cyfung1031 Sep 18, 2026
5b25310
🔒 validate sandbox message envelopes
cyfung1031 Sep 18, 2026
898fcc4
🔒 validate custom event envelopes
cyfung1031 Sep 18, 2026
35ce581
🔒 guard server action dispatch inputs
cyfung1031 Sep 18, 2026
276196c
🔒 inspect collection payload entries before cloning
cyfung1031 Sep 18, 2026
c783a7a
🔒 validate collection RPC payloads without accessors
cyfung1031 Sep 18, 2026
671c445
🔒 remove live document references from CAT fetch
cyfung1031 Sep 18, 2026
284b968
🔒 bind early-start wrappers to document URLs
cyfung1031 Sep 18, 2026
3693b58
🔒 reject page RPC replay window overflow
cyfung1031 Sep 18, 2026
9cf16de
🔒 close service worker page RPC replay window
cyfung1031 Sep 18, 2026
9dd323e
🔒 validate page RPC identity before replay state
cyfung1031 Sep 18, 2026
2acb238
🔒 harden GM value result records
cyfung1031 Sep 18, 2026
39b695d
🔒 restrict script attachment reads
cyfung1031 Sep 18, 2026
c46dfe1
🔒 keep MAIN script payload off page bridge
cyfung1031 Sep 18, 2026
deea129
🔒 isolate service worker value records
cyfung1031 Sep 18, 2026
71022c7
🔒 serialize CDP monitor transitions
cyfung1031 Sep 18, 2026
8528137
🔒 allow long-lived page RPC bindings
cyfung1031 Sep 18, 2026
96c577c
🔒 preserve early wrappers across same-document navigation
cyfung1031 Sep 18, 2026
6ee8ba4
🔒 require a native MAIN page-load handshake
cyfung1031 Sep 18, 2026
babadbc
✅ bound E2E waits and replay invariant tests
cyfung1031 Sep 18, 2026
0541cdb
🔧 restore PR E2E timeout settings
cyfung1031 Sep 18, 2026
3217aca
🔒 route MAIN bootstrap over extension transport
cyfung1031 Sep 18, 2026
dbad992
🔒 restore MAIN bootstrap page load
cyfung1031 Sep 19, 2026
0057ee8
⚡️ 优化跨上下文消息解析热路径
cyfung1031 Sep 19, 2026
cf6cf21
⚡️ 精简跨上下文消息体校验
cyfung1031 Sep 19, 2026
2d8a75a
⚡️ reuse PageMessage connection sender
cyfung1031 Sep 19, 2026
5b07c7e
⚡️ 优化 structuredClone 调用
cyfung1031 Sep 19, 2026
dcd220c
📚 更新 Agent 与消息传输架构文档
cyfung1031 Sep 19, 2026
d9cb85c
📄 Pareto review tracked documentation
cyfung1031 Sep 19, 2026
1937c31
🧪 修复 Vitest 测试框架版本固定
cyfung1031 Sep 20, 2026
46b639a
Merge remote-tracking branch 'origin/main' into codex/main-world-secu…
cyfung1031 Sep 20, 2026
6a471df
revert sctest version from 8d6f7eb7319601d0c76a58595803dcbf37b24c12 t…
cyfung1031 Sep 20, 2026
973f0c1
🔒 harden MAIN-world userscript capabilities
cyfung1031 Sep 20, 2026
3bf259f
📝 clarify MAIN-world transport and execution
cyfung1031 Sep 20, 2026
04b9ff5
Revert "📝 clarify MAIN-world transport and execution"
cyfung1031 Sep 20, 2026
164b07e
Revert "🔒 harden MAIN-world userscript capabilities"
cyfung1031 Sep 20, 2026
4691fa7
🔒 revert descriptor-as-authentication drift in MAIN-world mount
cyfung1031 Sep 20, 2026
fc195a8
✅ lock MAIN-world fallback compatibility
cyfung1031 Sep 20, 2026
4b08699
🔒 harden userscript wrapper provenance
cyfung1031 Sep 20, 2026
4b9b7d3
🔒 use template interpolation for wrapper validation
cyfung1031 Sep 20, 2026
989bc31
🔒 harden userscript sandbox intrinsics
cyfung1031 Sep 20, 2026
5e36545
🔒 restore captured wrapper source validation
cyfung1031 Sep 20, 2026
6f4a94e
🧹 simplify MAIN fallback regression coverage
cyfung1031 Sep 20, 2026
76f7fea
🔒 reject stale early-start privilege binding
cyfung1031 Sep 21, 2026
50853d7
🔒 bound page GM replay state and tighten validation
cyfung1031 Sep 21, 2026
a01653b
🔒 bind compiled revisions to registered userscripts
cyfung1031 Sep 21, 2026
2f06a1c
🔒 bind early wrappers to compiled revisions
cyfung1031 Sep 21, 2026
23cd962
📝 document MAIN fallback security boundary
cyfung1031 Sep 21, 2026
487bfb8
🔒 attach executionHandle to MAIN-world page RPC requests
cyfung1031 Sep 21, 2026
bd39276
🔒 unify context-menu grant policy across page RPC consumers
cyfung1031 Sep 21, 2026
311e133
🔒 restrict executionHandle to the direct-SW page RPC transport
cyfung1031 Sep 21, 2026
232a331
⚡️ compact the generated MAIN-world wrapper source
cyfung1031 Sep 21, 2026
c3a1fd3
`Native.functionToString` is not necessary. (over-engineering)
cyfung1031 Sep 21, 2026
7f08c4a
`structuredClone` function binding is not necessary. (over-engineering)
cyfung1031 Sep 21, 2026
5d95b05
Revert "`Native.functionToString` is not necessary. (over-engineering)"
cyfung1031 Sep 21, 2026
7e4e277
⚡️ skip descriptor machinery for the null-prototype event-descriptor map
cyfung1031 Sep 21, 2026
06c090e
⚡️ assign directly into GM_getValues' null-prototype result record
cyfung1031 Sep 21, 2026
2198a52
⚡️ assign directly into getScriptValueDetails' null-prototype record
cyfung1031 Sep 21, 2026
5d9b567
🔒 harden Native.bind argument delivery
cyfung1031 Sep 21, 2026
2062b5f
🐛 allow replay windows to advance across large forward gaps
cyfung1031 Sep 21, 2026
c150157
🔒 narrow Page RPC v2 wire identity to handle
cyfung1031 Sep 21, 2026
4c2454a
🔒 harden value-listener storage and invocation
cyfung1031 Sep 22, 2026
92fcb97
Merge remote-tracking branch 'origin/main' into claude/pr1747-pareto-…
cyfung1031 Sep 22, 2026
9055980
🔒 simplify context lifecycle visibility boundary
cyfung1031 Sep 22, 2026
601e550
♻️ remove pseudo-window descriptor scaffolding
cyfung1031 Sep 22, 2026
caf1e26
🔒 bind and migrate normal wrappers to compiled revisions
cyfung1031 Sep 22, 2026
efd82a7
🔒 reject normal wrappers from a different compiled revision
cyfung1031 Sep 22, 2026
c6894af
🔒 fix compiled wrapper closure binding
cyfung1031 Sep 22, 2026
7a04703
🔒 constrain page-load keys before runtime object merge
cyfung1031 Sep 22, 2026
57de77b
✅ lock runtime merge prototype invariants
cyfung1031 Sep 22, 2026
04cbba2
🔒 validate CAT stream events at page-bridge ingestion
cyfung1031 Sep 22, 2026
75732b5
Revert "🔒 validate CAT stream events at page-bridge ingestion"
cyfung1031 Sep 22, 2026
8caf020
Revert "✅ lock runtime merge prototype invariants"
cyfung1031 Sep 22, 2026
9b41f65
Revert "🔒 constrain page-load keys before runtime object merge"
cyfung1031 Sep 22, 2026
fafb56f
🔒 validate CAT stream events at page-bridge ingestion
cyfung1031 Sep 22, 2026
41b55e7
🔒 install trusted state as own data properties instead of Object.assign
cyfung1031 Sep 22, 2026
c42f058
Merge branch 'main' into codex/main-world-security-refactor
cyfung1031 Sep 22, 2026
e95fce8
refactor(message): hide MAIN bridge behind keyed performance events
cyfung1031 Sep 23, 2026
d02ae34
refactor(main-world): remove native fallback state machine
cyfung1031 Sep 23, 2026
0c6d815
✅ verify MAIN keyed bridge bootstrap
cyfung1031 Sep 23, 2026
cbccf45
docs(message): document keyed MAIN bridge policy
cyfung1031 Sep 23, 2026
0ee327e
🎨 format keyed message transport
cyfung1031 Sep 23, 2026
29e2b88
📄 correct MAIN bridge documentation
cyfung1031 Sep 23, 2026
12372d2
🔒 isolate deferred navigation URL checks
cyfung1031 Sep 23, 2026
ba6f24e
🐛 support Node MessageChannel fallback
cyfung1031 Sep 23, 2026
2b59e40
🔒 route sandbox traffic through private MessagePort
cyfung1031 Sep 23, 2026
c6e5551
🧪 make sandbox MessagePort leak E2E event-driven
cyfung1031 Sep 23, 2026
43cae45
🔒 harden private MessagePort event reads
cyfung1031 Sep 23, 2026
2070210
📚 document private sandbox MessagePort boundary
cyfung1031 Sep 23, 2026
c6e16a0
fix coding
cyfung1031 Sep 23, 2026
c08a879
🐛 avoid browser MessageChannel getter invocation
cyfung1031 Sep 23, 2026
0c810f0
📚 document MessageChannel build fallback
cyfung1031 Sep 24, 2026
39bd3cd
fix(gm): restore userscript storage clone compatibility
cyfung1031 Sep 24, 2026
2639098
test(gm): cover storage clone compatibility semantics
cyfung1031 Sep 24, 2026
e09d053
test(gm): align proxy expectations with compatibility fallback
cyfung1031 Sep 24, 2026
e57e202
fix(early-start): restore synchronous preload state
cyfung1031 Sep 24, 2026
a4625f4
fix(early-start): preserve pre-bootstrap value writes
cyfung1031 Sep 24, 2026
8f54306
perf(early-start): prefetch authoritative page bootstrap
cyfung1031 Sep 24, 2026
415fe43
style(early-start): format bootstrap prefetch
cyfung1031 Sep 24, 2026
b6152a4
fix(early-start): normalize bootstrap prefetch formatting
cyfung1031 Sep 24, 2026
34f3131
test(early-start): lock first-line synchronous GM state
cyfung1031 Sep 24, 2026
16d1ef0
fix(value): serialize early snapshot refresh with storage commits
cyfung1031 Sep 24, 2026
536b9a9
fix(early-start): refresh shared storage snapshots atomically
cyfung1031 Sep 24, 2026
617d935
refactor(early-start): decouple storage values from script revision
cyfung1031 Sep 24, 2026
a66ca1d
test(early-start): isolate snapshot batch assertions
cyfung1031 Sep 24, 2026
cf296a4
perf(early-start): keep value refresh out of static caches
cyfung1031 Sep 24, 2026
6838d2f
test(early-start): lock promise storage freshness barrier
cyfung1031 Sep 24, 2026
1898b8a
style(early-start): match runtime formatting
cyfung1031 Sep 24, 2026
bb583f8
fix(storage): await mutation freshness before UI success
cyfung1031 Sep 24, 2026
b9c7480
fix(early-start): serialize registration mutations
cyfung1031 Sep 24, 2026
2404c5e
style(early-start): normalize registration update method
cyfung1031 Sep 24, 2026
eba8a38
test(gm): add storage clone compatibility userscript
cyfung1031 Sep 24, 2026
c4c45f6
style(test): format storage clone e2e
cyfung1031 Sep 24, 2026
6cccc00
fix(gm): resolve async value writes from RPC completion
cyfung1031 Sep 24, 2026
efe6226
fix(early-start): recover snapshot refresh without blocking storage
cyfung1031 Sep 24, 2026
bbab274
test(early-start): fix snapshot refresh coverage
cyfung1031 Sep 24, 2026
9857747
perf(early-start): reuse committed values and page cache
cyfung1031 Sep 24, 2026
7d8e3fb
test(early-start): lock value refresh fast path
cyfung1031 Sep 24, 2026
6f6beb5
test(early-start): stabilize snapshot refresh assertions
cyfung1031 Sep 24, 2026
11561c7
fix(early-start): isolate snapshot maintenance failures
cyfung1031 Sep 24, 2026
cab82e9
fix(gm): preserve async batch rejection semantics
cyfung1031 Sep 24, 2026
2fb51b3
style(early-start): match runtime prettier layout
cyfung1031 Sep 24, 2026
0d9c602
lint fix
cyfung1031 Sep 24, 2026
270ff47
lint(gm): remove obsolete value update id binding
cyfung1031 Sep 24, 2026
76e7ce4
fix(gm): normalize storage values before local mutation
cyfung1031 Sep 24, 2026
917b48d
test(gm): lock storage value normalization compatibility
cyfung1031 Sep 24, 2026
7a8210b
test(gm): allow ScriptCat and Tampermonkey top-level storage results
cyfung1031 Sep 24, 2026
a60caa1
test(e2e): surface page errors before SCTest timeout
cyfung1031 Sep 24, 2026
0d954f9
Revert "test(e2e): surface page errors before SCTest timeout"
cyfung1031 Sep 24, 2026
4625b06
fix(values): encode non-finite numbers losslessly
cyfung1031 Sep 27, 2026
8b6adca
fix(gm): align all-values dictionary shape
cyfung1031 Sep 27, 2026
d0cac19
fix(gm): align storage serialization with measured behavior
cyfung1031 Sep 27, 2026
dd0e17c
fix(gm): align top-level BigInt storage behavior
cyfung1031 Sep 27, 2026
c2316e0
test(gm): lock deep storage compatibility behavior
cyfung1031 Sep 27, 2026
778f8ed
test(gm): expand deep storage persistence matrix
cyfung1031 Sep 27, 2026
ac5a0d8
test(gm): accept measured cross-manager storage variants
cyfung1031 Sep 27, 2026
6394630
test(gm): separate transient storage compatibility states
cyfung1031 Sep 27, 2026
27e8d2c
test(e2e): fail fast on userscript startup errors
cyfung1031 Sep 27, 2026
b1f88e5
🐛 avoid replying to disconnected RPC callers
cyfung1031 Sep 27, 2026
1faba89
✅ compare storage snapshots independent of key order
cyfung1031 Sep 27, 2026
da06f27
✅ handle expected GM XHR abort rejection
cyfung1031 Sep 27, 2026
a07d5cd
✅ use the E2E error buffer constant
cyfung1031 Sep 27, 2026
b4eca47
♻️ reuse shared page message envelope
cyfung1031 Sep 27, 2026
277ce9a
♻️ simplify sandbox channel bootstrap marker
cyfung1031 Sep 27, 2026
5aaadd5
♻️ narrow CAT stream event validation
cyfung1031 Sep 27, 2026
010726d
🧪 matrix unsupported top-level storage values
cyfung1031 Sep 27, 2026
9d41b5c
🧪 matrix effective grants across page worlds
cyfung1031 Sep 27, 2026
203b63a
🧪 reuse early execution fixture in executor tests
cyfung1031 Sep 27, 2026
d04d2fe
♻️ remove redundant page RPC declarations
cyfung1031 Sep 27, 2026
062c5b6
♻️ centralize USER_SCRIPT delivery match
cyfung1031 Sep 27, 2026
2c9f226
📝 shorten data installer comments
cyfung1031 Sep 27, 2026
5d2d709
🧪 matrix early snapshot failure outcomes
cyfung1031 Sep 27, 2026
315d278
✅ consolidate GM storage example tests
cyfung1031 Sep 28, 2026
9b09dc0
✅ run GM storage suites from one URL
cyfung1031 Sep 28, 2026
1b52de9
🔀 sync latest main into PR #1747
cyfung1031 Sep 28, 2026
735dc75
♻️ reuse WindowMessageConnect for page event channels
cyfung1031 Sep 28, 2026
bc83cab
🧪 consolidate early-start executor fixtures
cyfung1031 Sep 28, 2026
9dfb1d3
🧪 matrix repeated page RPC policy regressions
cyfung1031 Sep 28, 2026
a758ca7
🧪 fix GM XHR E2E summary accounting
cyfung1031 Sep 29, 2026
ee351f7
Update gm_storage_test.js
cyfung1031 Sep 29, 2026
5f8a64b
test(e2e): align GM storage summary expectation
cyfung1031 Sep 29, 2026
8ad8eed
Update gm-api.spec.ts
cyfung1031 Sep 29, 2026
cc19578
Merge branch 'main' into codex/main-world-security-refactor
cyfung1031 Sep 29, 2026
33065d6
chore: remove unused SC_ZN_RAND define
cyfung1031 Sep 29, 2026
88594ad
refactor: make stream shape assertions type-only
cyfung1031 Sep 29, 2026
1a890a2
引入 realmBridgeToken 减低监听风险
cyfung1031 Sep 29, 2026
5a7ea5d
realmBridgeToken -> realmBridgeFaceID
cyfung1031 Sep 30, 2026
f9fb38f
replace the negotiateEventFlag design by realmBridgeEventFlag
cyfung1031 Sep 30, 2026
397645d
fix vitest
cyfung1031 Sep 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Service Worker (src/service_worker.ts)
├── ExtensionMessage ──────────────→ Content Script (src/content.ts)
│ └── CustomEventMessage ──→ Inject Script (src/inject.ts)
└── ServiceWorkerMessageSend ──────→ Offscreen (src/offscreen.ts) (Chrome; Firefox uses EventPageOffscreenManager)
└── WindowMessage ──→ Sandbox (src/sandbox.ts)
└── private MessagePort ──→ Sandbox (src/sandbox.ts)
```

> SW → Offscreen uses `ServiceWorkerMessageSend` (`clients.matchAll()` + `postMessage`) on Chrome and
Expand All @@ -244,8 +244,9 @@ Sandbox.

### Message Passing (`packages/message/`)

`ExtensionMessage` (chrome.runtime — SW ↔ Content / Inject / Offscreen), `WindowMessage` (postMessage — Offscreen ↔
Sandbox), `ServiceWorkerMessageSend` (`clients.matchAll()` + `postMessage` — SW → Offscreen on Chrome),
`ExtensionMessage` (chrome.runtime — SW ↔ Content / Inject / Offscreen), `MessagePortMessage` +
`SandboxChannelHost` (one-shot Window bootstrap, then private MessagePort — Offscreen/EventPage ↔ Sandbox),
`ServiceWorkerMessageSend` (`clients.matchAll()` + `postMessage` — SW → Offscreen on Chrome),
`CustomEventMessage` (CustomEvent — Content ↔ Inject), and `MessageQueue` (cross-context broadcast).

### Service & Data Layers
Expand Down
2 changes: 1 addition & 1 deletion docs/DOC-MAINTENANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ of sanitization patterns can otherwise look like matches — so don't rely on a
| [`design.md`](./design.md) | The design system; tokens, component palette, and layout/motion/state/a11y patterns → the three `references/design-*.md`. |
| [`verification.md`](./verification.md) | *When* to drive the real built extension, where its evidence goes, how to report honestly. Not the harness — link to `e2e/README.md`, don't restate fixtures/isolation/env vars. |
| [`../e2e/README.md`](../e2e/README.md) | The harness itself: the two tracks and their configs, isolation, fixture/helper inventory, protocol mocks, `E2E_*` variables, artifact paths. |
| [`architecture.md`](./architecture.md) | Deep internals; subsystem deep-dives → the six `references/architecture-*.md`. |
| [`architecture.md`](./architecture.md) | Deep internals; subsystem deep-dives → `references/architecture-*.md` and [`references/main-world-message-privacy.md`](./references/main-world-message-privacy.md). |
| [`cloud-sync.md`](./cloud-sync.md) | Cloud sync internals: sync files, digest/status semantics, provider differences, error classification, retry policy. |
| [`translation.md`](./translation.md) | Translation / localization single source of truth. |
| [`DOC-MAINTENANCE.md`](./DOC-MAINTENANCE.md) | This guide: organization rules, fact-check / anti-drift discipline, policy-consistency checks — across every tracked contributor Markdown, not just `AGENTS.md` + `docs/*`. |
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| [`design.md`](./design.md) | 设计系统参考:主题机制、shadcn 组件选型、新建页面配方总览;令牌完整值拆到 [`references/design-tokens.md`](./references/design-tokens.md),组件清单拆到 [`references/design-components.md`](./references/design-components.md),布局/响应式/动效/状态/无障碍范式拆到 [`references/design-patterns.md`](./references/design-patterns.md)。**做页面/对话框/区块前先读。** |
| [`../e2e/README.md`](../e2e/README.md) | E2E 测试台手册:两条赛道(committed smoke / gitignored scratch)、浏览器与 profile 隔离、fixtures 与 helper 清单、协议 mock、`E2E_*` 环境变量、产物与失败排查路径。**跑 / 写 E2E 或一次性验证脚本前先读。** |
| [`verification.md`](./verification.md) | 功能验证指南:启一个常驻会话(默认无头、可多 worktree 并发)逐条命令驱动真实扩展,只在需要复现顺序/时序时才写 spec,不跑全量 E2E、不加永久用例;驱动方法(GM API in-page self-test、SW 消息、主题)拆到 [`references/verification-methods.md`](./references/verification-methods.md),报告模板拆到 [`references/verification-report-template.md`](./references/verification-report-template.md),调试 FAQ 拆到 [`references/verification-debugging.md`](./references/verification-debugging.md)。**验证改动是否真正跑通时读。** |
| [`architecture.md`](./architecture.md) | 内部原理总览:多进程模型、消息传递;各子系统深入拆到 [`references/architecture-services.md`](./references/architecture-services.md)(服务层)、[`references/architecture-data.md`](./references/architecture-data.md)(数据层)、[`references/architecture-gm-api.md`](./references/architecture-gm-api.md)(GM API)、[`references/architecture-execution.md`](./references/architecture-execution.md)(脚本执行)、[`references/architecture-build.md`](./references/architecture-build.md)(构建管线)、[`references/architecture-agent.md`](./references/architecture-agent.md)(Agent 子系统)。 |
| [`architecture.md`](./architecture.md) | 内部原理总览:多进程模型、消息传递;各子系统深入拆到 [`references/architecture-services.md`](./references/architecture-services.md)(服务层)、[`references/architecture-data.md`](./references/architecture-data.md)(数据层)、[`references/architecture-gm-api.md`](./references/architecture-gm-api.md)(GM API)、[`references/architecture-execution.md`](./references/architecture-execution.md)(脚本执行)、[`references/main-world-message-privacy.md`](./references/main-world-message-privacy.md)(MAIN 消息隐私与回退策略)、[`references/sandbox-message-port-security.md`](./references/sandbox-message-port-security.md)(Sandbox 私有 MessagePort 威胁模型与验证)、[`references/architecture-build.md`](./references/architecture-build.md)(构建管线)、[`references/architecture-agent.md`](./references/architecture-agent.md)(Agent 子系统)。 |
| [`cloud-sync.md`](./cloud-sync.md) | 云同步实现说明:同步文件语义、主流程、状态合并、provider 差异、错误分类、retry 策略和维护注意事项。 |
| [`DOC-MAINTENANCE.md`](./DOC-MAINTENANCE.md) | 文档维护与事实核对指南:组织规则、逐条核对清单、跨文档政策一致性核对、隐私清理、以及在 resolved final tree 上的复核方法,覆盖全部 tracked 的 agent/contributor Markdown(不止 `AGENTS.md` + `docs/*`,还包括 `.github/*.md`、package-local README)。**改/审文档前先读。** |

Expand Down
63 changes: 34 additions & 29 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ into several sandboxed JavaScript realms that cannot share memory; ScriptCat the
Three ideas explain almost everything in the codebase:

- **Contexts are processes.** Each entry point (`service_worker`, `content`, `inject`, `offscreen`, `sandbox`)
is an isolated realm. They never share objects — only serializable messages.
is an isolated realm. They do not share ordinary mutable objects — cross-context state moves through serialized or transferable messages.
- **One message layer, several transports.** [`packages/message`](../packages/message) abstracts
`chrome.runtime`, `postMessage`, and DOM `CustomEvent` behind a single RPC + pub/sub API, so services are
written against interfaces (`Server`/`Group`/`Client`/`IMessageQueue`), not raw browser APIs.
Expand All @@ -62,9 +62,10 @@ Three ideas explain almost everything in the codebase:
│ bridges SW ↔ inject │ │ DOM-capable background │
│ Server("content") │ │ Server("offscreen") │
└──────────┬───────────┘ └─────────────┬────────────┘
CustomEventMessage WindowMessage
(DOM CustomEvent) (window.postMessage)
▼ ▼
CustomEventMessage SandboxChannelHost
(DOM CustomEvent) one-shot Window bootstrap
▼ + private MessagePort
▼
┌──────────────────────┐ ┌──────────────────────────┐
│ INJECT SCRIPT │ │ SANDBOX (iframe) │
│ page realm, │ │ with(){} script eval, │
Expand All @@ -77,6 +78,12 @@ Three ideas explain almost everything in the codebase:
inject, and sandbox don't hold a MessageQueue instance.
```

The diagram compresses the page-facing routes: USER_SCRIPT content uses a native extension channel after bootstrap, while MAIN inject intentionally uses a single keyed performance-event bridge through `scripting`. The `scripting` bundle is a
document-start extension content script registered per matching frame; it runs a page-bridge runtime and is a
supporting per-document helper rather than a separate service/background context in this five-context model.
`CustomEventMessage` carries the content bootstrap
handoff and synchronous DOM handles; `PageEventMessage` carries MAIN pageLoad, runtime event/value updates, the whitelisted `external.Scriptcat` API, and validated GM RPC through the isolated `scripting` broker. It uses a random event name on `performance`, not the global `window.message` bus. The bridge itself is not an authenticated extension origin.

---

## The Five Contexts (Process Model)
Expand All @@ -86,13 +93,15 @@ Each context is a separate bundle (see [Build pipeline & manifest](./references/
| Context | Entry | Realm / capabilities | Bootstraps |
|---|---|---|---|
| **Service Worker** | [`src/service_worker.ts`](../src/service_worker.ts) | No DOM. Owns `chrome.*` privileged APIs, storage, permissions, routing. | `ExtensionMessage(true)` → `Server("serviceWorker")` + `MessageQueue` → `ServiceWorkerManager` |
| **Content** | [`src/content.ts`](../src/content.ts) | Isolated content-script world. Bridges SW and the page. | `CustomEventMessage` channel to inject + `Server("content")` → `ScriptRuntime` |
| **Inject** | [`src/inject.ts`](../src/inject.ts) | Page (`MAIN`) world. Has `unsafeWindow`; runs page userscripts. | `CustomEventMessage` to content + `Server("inject")` |
| **Offscreen** | [`src/offscreen.ts`](../src/offscreen.ts) | DOM-capable background page (Blobs, clipboard, DOM scraping, local storage). | `ExtensionMessage()` + `WindowMessage(window, sandbox)` → `OffscreenManager` |
| **Sandbox** | [`src/sandbox.ts`](../src/sandbox.ts) | `sandbox`ed iframe inside offscreen. Evaluates background/scheduled scripts; runs cron. | `WindowMessage(window, parent)` + `Server("sandbox")` → `SandboxManager` |
| **Content** | [`src/content.ts`](../src/content.ts) | `USER_SCRIPT` world. Receives a document bootstrap token through the page-side bridge, then uses a native extension channel for script loading, GM RPC, value updates, and callbacks. Dedicated USER_SCRIPT listeners are used when available; otherwise the regular port is token-bound. | `ExtensionMessage` + native callback port → `Server("content")` → `ScriptRuntime`; `CustomEventMessage` for bootstrap handoff and DOM handles |
| **Inject** | [`src/inject.ts`](../src/inject.ts) | Page (`MAIN`) world. Has `unsafeWindow`; runs page userscripts. | `PageEventMessage` keyed performance-event bridge → `scripting`; broker/SW validate privileged RPC; `CustomEventMessage` for synchronous DOM handles |
| **Offscreen** | [`src/offscreen.ts`](../src/offscreen.ts) | DOM-capable background page (Blobs, clipboard, DOM scraping, local storage). | SW receiver + `SandboxChannelHost`; parent installs the one-shot bootstrap listener before attaching the sandbox iframe |
| **Sandbox** | [`src/sandbox.ts`](../src/sandbox.ts) | `sandbox`ed iframe inside offscreen/event page. Evaluates background/scheduled scripts; runs cron. | creates `MessageChannel`, wires `MessagePortMessage` + `Server("sandbox")`, then transfers the peer port to the parent as the readiness signal |

There is also a sixth bundle, [`src/scripting.ts`](../src/scripting.ts), injected via `chrome.userScripts` /
`chrome.scripting` to carry the compiled page-script payload (see [Script execution](./references/architecture-execution.md)).
The [`scripting` bundle](../src/scripting.ts) is a document-start content script registered through
`chrome.scripting`; it supplies the per-document page bridge. Compiled userscript payloads and the `inject.js` /
`content.js` runners are registered separately through `chrome.userScripts` (see
[Script execution](./references/architecture-execution.md)).

### Service-worker bootstrap

Expand Down Expand Up @@ -126,22 +135,17 @@ already has DOM and plays the offscreen role directly.
`ExtensionMessage` (`chrome.runtime`).
- **Firefox:** [`EventPageOffscreenManager`](../src/app/service/offscreen/event_page_manager.ts) substitutes
for the offscreen document; its sandbox iframe is a `sandbox` manifest page, which Firefox 154+ loads as a
cross-origin frame (`contentDocument` is `null`, `contentWindow.location` is unreadable). Only the sandbox
itself knows when it's actually ready, so the parent never polls or pings it: `SandboxManager`
([`src/app/service/sandbox/index.ts`](../src/app/service/sandbox/index.ts)) proactively posts a
`preparationSandbox` message once its own `Server` is wired up (same mechanism on both platforms), and
[`BackgroundEnvManagerBase.preparationSandbox`](../src/app/service/offscreen/base.ts) immediately tells the
service worker `preparationOffscreen({ verified: true })` — no round trip, no waiting. The service worker
replays enabled background/scheduled scripts and the current language only for this verified signal, once.
Separately and non-blockingly, the
sandbox reuses its own in-flight `getExtensionEnv` request to self-check that the channel is genuinely
bidirectional, and reports the outcome via `reportSandboxChannelHealth`, which the parent logs (visible in
the parent's own console/log, since the sandbox iframe's console is far less discoverable). If the sandbox
never announces readiness at all (iframe failed to load, script error), a fallback timer in
`BackgroundEnvManagerBase` still tells the service worker `preparationOffscreen({ verified: false })` after
`SANDBOX_READY_FALLBACK_MS`, logging a clear error instead of hanging forever. That unverified notification
does not send initialization through an unavailable channel; if the real handshake arrives later, the
verified state replay still occurs exactly once.
cross-origin frame (`contentDocument` is `null`, `contentWindow.location` is unreadable). The sandbox transport
is nevertheless the same as Chromium: the parent first installs a `SandboxChannelHost` bootstrap listener,
then attaches the iframe. After `sandbox.ts` has wired its `Server` and `Runtime`, it creates/transfers one
`MessagePort` to the parent. The parent accepts that capability only when `event.source` is the exact sandbox
`contentWindow`, removes the global Window `"message"` listener immediately, and uses the private port for all
subsequent traffic. Receiving the port is also the only verified sandbox-readiness signal; only then does
`BackgroundEnvManagerBase` call `preparationOffscreen({ verified: true })`, which lets the service worker replay
enabled background/scheduled scripts and language state. There is no second `preparationSandbox` RPC, health
ping, or unverified timeout-ready path. The transport threat model, same-realm prototype hardening, failure
semantics, and verification matrix are documented in
[Private Offscreen/EventPage ↔ Sandbox MessagePort](./references/sandbox-message-port-security.md).

Firefox packages use `incognito: "spanning"`, so normal and private page scripts share one event page but retain
their own `sender.tab.incognito` value for global-switch checks, `@run-in`, and `GM_info.isIncognito`. Background
Expand All @@ -167,9 +171,10 @@ communication styles** over **several transports**.

| Class | File | Connects | Underlying API |
|---|---|---|---|
| `ExtensionMessage` | [`extension_message.ts`](../packages/message/extension_message.ts) | SW ↔ Content / Inject / Offscreen | `chrome.runtime.sendMessage` / `onConnect` (+ `onUserScript*` on Firefox) |
| `CustomEventMessage` | [`custom_event_message.ts`](../packages/message/custom_event_message.ts) | Content ↔ Inject | DOM `CustomEvent` dispatch (bypasses page tampering) |
| `WindowMessage` | [`window_message.ts`](../packages/message/window_message.ts) | Offscreen ↔ Sandbox | `window.postMessage` |
| `ExtensionMessage` | [`extension_message.ts`](../packages/message/extension_message.ts) | SW ↔ Content / Inject / Offscreen | `chrome.runtime.sendMessage` / `onConnect`; browser-identified USER_SCRIPT messages are action-gated, and regular-port fallbacks are token-bound |
| `PageEventMessage` | [`page_event_message.ts`](../packages/message/page_event_message.ts) | `scripting` ↔ Inject | Keyed `performance` `CustomEvent`; MAIN pageLoad, runtime updates, whitelisted external API, and GM RPC routed through the isolated broker and validated by `PageRpcRegistry` |
| `CustomEventMessage` | [`custom_event_message.ts`](../packages/message/custom_event_message.ts) | Content ↔ `scripting` page helper | DOM `CustomEvent`; bootstrap handoff and synchronous DOM references, not privileged GM RPC |
| `MessagePortMessage` / `SandboxChannelHost` | [`message_port_message.ts`](../packages/message/message_port_message.ts), [`sandbox_message_channel.ts`](../packages/message/sandbox_message_channel.ts) | Offscreen/EventPage ↔ Sandbox | sandbox-created `MessageChannel`; one strict source-checked Window bootstrap transfers the peer port, then all payloads use the private `MessagePort` |
| `ServiceWorkerMessageSend` | [`window_message.ts`](../packages/message/window_message.ts) | SW → Offscreen (Chrome) | `clients.matchAll()` + `postMessage` |
| `MessageQueue` | [`message_queue.ts`](../packages/message/message_queue.ts) | Broadcast among the contexts that instantiate it — SW, Offscreen, UI pages | `chrome.runtime.sendMessage` + local `EventEmitter3` |
| `MockMessage` | [`mock_message.ts`](../packages/message/mock_message.ts) | Tests | in-memory `EventEmitter3` |
Expand Down
2 changes: 1 addition & 1 deletion docs/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
```bash
pnpm install # install deps (preinstall enforces pnpm)
pnpm run dev # dev build (source maps); load dist/ext as unpacked extension
pnpm run dev:noMap # dev build w/o source maps (incognito)
pnpm run dev:noMap # dev build w/o source maps
pnpm run build # production Rspack build
pnpm run pack # package the extension (requires dist/scriptcat.pem)

Expand Down
Loading
Loading