Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7680176
⚡️ GM 值更新改为定向推送给运行该脚本的标签页,不再经 storage.local 广播到所有 frame
CodFrm Nov 9, 2026
02d3dba
✨ Add indexed GM value Port subscriptions and reconnecting client
cyfung1031 Nov 9, 2026
59cb389
⚡️ Route GM updates directly to subscribed frame Ports
cyfung1031 Nov 9, 2026
baa60b6
🐛 Recover failed value Ports and discard stale bfcache connections
cyfung1031 Nov 10, 2026
67c76d4
⚡ Return durable GM write receipts independently of Port delivery
cyfung1031 Nov 11, 2026
dc09972
🐛 Settle GM writes via verified RPC receipts and deduplicate notifica…
cyfung1031 Nov 11, 2026
b33b595
🐛 Recover immediately after SW disconnect; stop on invalid extension …
cyfung1031 Nov 11, 2026
a9f8101
🐛 Reject failed extension RPC callbacks instead of treating missing r…
cyfung1031 Nov 11, 2026
ccd3191
🐛 Bound initial page-load retries and handle subscription failures
cyfung1031 Nov 11, 2026
69510f1
✅ Cover durable write receipts, deduplication, terminal context and i…
cyfung1031 Nov 11, 2026
3e0c1f1
✅ Verify no-op/delete receipts and extension transport errors
cyfung1031 Nov 11, 2026
71fa97a
✅ Isolate timer tests and maintain strict TypeScript/format compatibi…
cyfung1031 Nov 11, 2026
539c583
✅ Cover bounded initial page-load retries and terminal failure
cyfung1031 Nov 11, 2026
842ef15
🐛 Reject invalid-context GM operations and isolate post-commit listen…
cyfung1031 Nov 11, 2026
794dde1
🧪 Use isolated timers and typed payloads in lifecycle regressions
cyfung1031 Nov 11, 2026
f4f425b
🐛 Avoid invalid-context bfcache reports and unhandled page-show rejec…
cyfung1031 Nov 11, 2026
ac157cb
🎨 Format receipt regressions and type out-of-order notifications
cyfung1031 Nov 11, 2026
c86429b
✅ Verify commit receipts after storage success and rejection on save …
cyfung1031 Nov 11, 2026
ca1bf34
🎨 Normalize receipt regression test formatting
cyfung1031 Nov 11, 2026
33355f2
⚡ Persist GM storage revisions and expose versioned snapshots
cyfung1031 Nov 11, 2026
0205651
⚡ Reconcile Port subscriptions only when persisted storage versions d…
cyfung1031 Nov 11, 2026
e3a6f0c
🐛 Provide authorized on-demand GM snapshots for version-gap recovery
cyfung1031 Nov 11, 2026
ebf4b7a
🐛 Preserve subscriptions across transient handshake timeouts and deli…
cyfung1031 Nov 11, 2026
770e2b5
🐛 Prevent out-of-order GM receipts from rolling cache state backward
cyfung1031 Nov 11, 2026
feb3c45
🐛 Apply reconciled snapshots in existing script worlds without replay…
cyfung1031 Nov 11, 2026
c66b6cf
🐛 Converge running frame caches and stage pre-injection version changes
cyfung1031 Nov 11, 2026
0e45261
🐛 Preserve ambiguous transport errors and contain failed logging RPCs
cyfung1031 Nov 11, 2026
a4ede08
🐛 Retry transient startup failures without reinjection and throttle s…
cyfung1031 Nov 11, 2026
329f877
✅ Preserve existing Port protocol compatibility and assert versioned …
cyfung1031 Nov 11, 2026
97e3c5d
✅ Regress out-of-order receipts, 128-ID eviction and persisted monoto…
cyfung1031 Nov 11, 2026
cfd9e03
✅ Test subscription recovery at 31s, selective snapshots and frame co…
cyfung1031 Nov 11, 2026
78429ed
✅ Test ambiguous Network Rules responses and failure-safe logging
cyfung1031 Nov 11, 2026
44fe1f4
🐛 Bound snapshot RPCs and reconcile early-start caches without re-exe…
cyfung1031 Nov 11, 2026
42b4423
🐛 Include persisted revision metadata in the explicit page-load wire …
cyfung1031 Nov 11, 2026
791cd6b
✅ Adapt runtime cache tests to versioned page-load value reads
cyfung1031 Nov 11, 2026
6c73a4a
🐛 Audit fire-and-forget GM RPCs and settle async Tab APIs on transpor…
cyfung1031 Nov 11, 2026
6400e0c
✅ Keep synchronous GM value tests on explicit persisted-write acknowl…
cyfung1031 Nov 11, 2026
799eb2d
🐛 Keep verified GM write completion independent of follow-up reconcil…
cyfung1031 Nov 11, 2026
38bed90
🐛 Recover Port connections that never send initial ready and release …
cyfung1031 Nov 11, 2026
9ad649d
✅ Regress a connected but unacknowledged SW Port handshake
cyfung1031 Nov 11, 2026
60f4b04
🐛 Fence stale subscription snapshots by request and storage generation
cyfung1031 Nov 11, 2026
445c3e8
✅ Cover stale-epoch snapshot fencing and versioned subscription corre…
cyfung1031 Nov 11, 2026
be49d9e
🐛 Refuse stale direct GM snapshots after a storage-generation change
cyfung1031 Nov 11, 2026
03c5d37
🐛 Normalize shared-storage startup snapshots to the latest revision
cyfung1031 Nov 11, 2026
a7a9d9d
🐛 Preserve GM user-config defaults during pre-injection snapshot reco…
cyfung1031 Nov 11, 2026
7da7f1a
🐛 Exclude metadata-only user-config entries from snapshot defaults
cyfung1031 Nov 11, 2026
4a90374
✅ Verify shared-storage and user-config snapshot consistency before i…
cyfung1031 Nov 11, 2026
36e595e
🎨 Keep frame-startup and reconciliation tests within project formatti…
cyfung1031 Nov 11, 2026
ec3db14
🐛 Keep user-config defaults out of persisted GM data and reconciliati…
cyfung1031 Nov 11, 2026
cbdd07a
✅ Test that page config defaults never contaminate persisted value sn…
cyfung1031 Nov 11, 2026
805e942
🐛 Keep a dirty refresh request across in-flight Port snapshot acknowl…
cyfung1031 Nov 11, 2026
a389a8c
🐛 Track observed GM revision gaps and repair failed script-world deli…
cyfung1031 Nov 11, 2026
3232a71
🐛 Preserve latest GM state for lazy userscript creation and acknowled…
cyfung1031 Nov 11, 2026
8645802
🐛 Retry only typed transient pageLoad transport failures with bounded…
cyfung1031 Nov 11, 2026
bf2062f
🐛 Reconcile GM-context revisions observed during an in-flight snapsho…
cyfung1031 Nov 11, 2026
f11639c
🐛 Acknowledge GM delivery only after its script world accepted the up…
cyfung1031 Nov 11, 2026
3a650a9
🐛 Require explicit script-world delivery receipts before considering …
cyfung1031 Nov 11, 2026
dbed62c
✅ Regress in-flight revision gaps, world delivery recovery, lazy scri…
cyfung1031 Nov 11, 2026
67eba9c
✅ Use the real encoded GM value wire format in deferred-execution reg…
cyfung1031 Nov 11, 2026
ad97328
🐛 Authorize internal GM value reconciliation for listener-only grants
cyfung1031 Nov 11, 2026
1601709
🐛 Back off repeated reconciliation failures and reject stale world-re…
cyfung1031 Nov 11, 2026
589e06f
🐛 Keep reconciling dirty worlds after snapshot reads until delivery i…
cyfung1031 Nov 11, 2026
089476b
🐛 Isolate per-script GM application failures while propagating world-…
cyfung1031 Nov 11, 2026
80c6787
⚡ Avoid allocating recovery arrays on the normal synchronous GM updat…
cyfung1031 Nov 11, 2026
dc7bcdf
✅ Regress per-script fault isolation and reject empty world delivery …
cyfung1031 Nov 11, 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: 7 additions & 0 deletions packages/message/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** Transport failure: a request may have executed although its response was lost. */
export class MessageResponseLostError extends Error {
constructor(message: string) {
super(message);
this.name = "MessageResponseLostError";
}
}
10 changes: 5 additions & 5 deletions packages/message/extension_message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import EventEmitter from "eventemitter3";
import type { Message, MessageConnect, MessageSend, RuntimeMessageSender, TMessage, TMessageCommAction } from "./types";
import { uuidv4 } from "@App/pkg/utils/uuid";
import { MessageResponseLostError } from "./errors";

const listenerMgr = new EventEmitter<string, any>(); // 单一管理器

Expand All @@ -17,15 +18,14 @@ export class ExtensionMessage implements Message {

// 发送消息 注意不进行回调的内存泄漏
sendMessage<T = any>(data: TMessage): Promise<T> {
return new Promise((resolve: ((value: T) => void) | null) => {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage(data, (resp: T) => {
const lastError = chrome.runtime.lastError;
if (lastError) {
console.error("chrome.runtime.lastError in chrome.runtime.sendMessage:", lastError);
// 通信API出错不回继续对话
reject(new MessageResponseLostError(lastError.message || "Extension message delivery failed"));
return;
}
resolve!(resp);
resolve = null;
resolve(resp);
});
});
}
Expand Down
31 changes: 31 additions & 0 deletions packages/message/extension_message_receipt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { ExtensionMessage } from "./extension_message";

describe("ExtensionMessage RPC response", () => {
afterEach(() => vi.unstubAllGlobals());

it("lastError rejects instead of resolving an absent response", async () => {
const runtime = {
lastError: { message: "Extension context invalidated" },
sendMessage: vi.fn((_request: unknown, callback: (response: unknown) => void) => callback(undefined)),
};
vi.stubGlobal("chrome", { runtime });
await expect(new ExtensionMessage().sendMessage({ action: "test" })).rejects.toThrow(
"Extension context invalidated"
);
});

it("successful void payload remains a valid transport response", async () => {
const runtime = {
lastError: undefined,
sendMessage: vi.fn((_request: unknown, callback: (response: unknown) => void) =>
callback({ code: 0, data: undefined })
),
};
vi.stubGlobal("chrome", { runtime });
await expect(new ExtensionMessage().sendMessage({ action: "test" })).resolves.toEqual({
code: 0,
data: undefined,
});
});
});
8 changes: 8 additions & 0 deletions src/app/logger/message_writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { SenderRuntime, Server } from "@Packages/message/server";
import MessageWriter from "./message_writer";

describe("MessageWriter 页面日志路由", () => {
it("已失效 context 导致日志发送失败时不能产生未处理 rejection", async () => {
const sender = { sendMessage: vi.fn().mockRejectedValue(new Error("Extension context invalidated")) };
const writer = MessageWriter.serviceWorker(sender as unknown as import("@Packages/message/types").MessageSend);
expect(() => writer.write("error", "closed", { env: "test" })).not.toThrow();
await Promise.resolve();
expect(sender.sendMessage).toHaveBeenCalledOnce();
});

it("页面调用方应将日志发送到 service worker 的 logger 处理器", () => {
const message = new MockMessage(new EventEmitter());
const handler = vi.fn();
Expand Down
5 changes: 3 additions & 2 deletions src/app/logger/message_writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default class MessageWriter implements Writer {
}

write(level: LogLevel, message: string, label: LogLabel): void {
this.msgSender.sendMessage({
// Logging is best-effort. Never recurse into the logger on transport failure.
void this.msgSender.sendMessage({
action: this.action,
data: {
id: 0,
Expand All @@ -24,6 +25,6 @@ export default class MessageWriter implements Writer {
label,
createtime: Date.now(),
},
});
}).catch(() => undefined);
}
}
2 changes: 2 additions & 0 deletions src/app/repo/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export type PageScriptResource = Record<string, { base64?: string; content: stri
export interface ScriptRunResource extends Script {
code: string; // 原始代码
value: ValueStore;
valueRevision?: number;
valueEpoch?: string;
flag: string;
resource: ScriptResource; // 资源列表,包含脚本需要的资源
resourceByType?: ScriptResourceByType;
Expand Down
4 changes: 4 additions & 0 deletions src/app/repo/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export interface Value {
data: { [key: string]: any };
createtime: number;
updatetime: number;
/** Persisted per-storageName ordering. Old records implicitly start at revision zero. */
revision?: number;
/** Changes when a storageName record is deleted and recreated. */
epoch?: string;
}

export class ValueDAO extends Repo<Value> {
Expand Down
10 changes: 7 additions & 3 deletions src/app/service/content/exec_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createContext, createProxyContext } from "./create_context";
import type { GMInfoEnv, ScriptFunc } from "./types";
import { compileScript, isContextMenuScript } from "./utils";
import type { Message } from "@Packages/message/types";
import type { ValueUpdateDataEncoded } from "./types";
import type { ValueSnapshot, ValueUpdateDataEncoded } from "./types";
import { evaluateGMInfo } from "./gm_api/gm_info";
import type { IGM_Base } from "./gm_api/gm_api";
import type { TScriptInfo } from "@App/app/repo/scripts";
Expand Down Expand Up @@ -74,8 +74,12 @@ export default class ExecScript {
this.sandboxContext?.emitEvent(event, eventId, data);
}

valueUpdate(data: ValueUpdateDataEncoded) {
this.sandboxContext?.valueUpdate(data);
valueUpdate(data: ValueUpdateDataEncoded): void | Promise<void> {
return this.sandboxContext?.valueUpdate(data);
}

valueSnapshot(snapshot: ValueSnapshot) {
this.sandboxContext?.valueSnapshot(snapshot);
}

execContext: any;
Expand Down
Loading
Loading