惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
B
Blog RSS Feed
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
D
Docker
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
C
Check Point Blog
The Cloudflare Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
量子位
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
T
The Blog of Author Tim Ferriss
博客园 - 【当耐特】
Vercel News
Vercel News
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
博客园 - 司徒正美

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(browser): ignore Playwright dialog race rejections · ...
openclaw-clo · 2026-04-29 · via Recent Commits to openclaw:main

@@ -0,0 +1,139 @@

1+

import { beforeEach, describe, expect, it, vi } from "vitest";

2+3+

const { getUnhandledRejectionHandlers, registerUnhandledRejectionHandlerMock, resetHandlers } =

4+

vi.hoisted(() => {

5+

let handlers: Array<(reason: unknown) => boolean> = [];

6+

return {

7+

getUnhandledRejectionHandlers: () => handlers,

8+

registerUnhandledRejectionHandlerMock: vi.fn((handler: (reason: unknown) => boolean) => {

9+

handlers.push(handler);

10+

return () => {

11+

handlers = handlers.filter((candidate) => candidate !== handler);

12+

};

13+

}),

14+

resetHandlers: () => {

15+

handlers = [];

16+

},

17+

};

18+

});

19+20+

const {

21+

ensureExtensionRelayForProfilesMock,

22+

getPwAiModuleMock,

23+

isPwAiLoadedMock,

24+

startTrackedBrowserTabCleanupTimerMock,

25+

stopKnownBrowserProfilesMock,

26+

trackedTabCleanupMock,

27+

} = vi.hoisted(() => {

28+

const trackedTabCleanupMock = vi.fn();

29+

return {

30+

ensureExtensionRelayForProfilesMock: vi.fn(async () => {}),

31+

getPwAiModuleMock: vi.fn(),

32+

isPwAiLoadedMock: vi.fn(() => false),

33+

startTrackedBrowserTabCleanupTimerMock: vi.fn(() => trackedTabCleanupMock),

34+

stopKnownBrowserProfilesMock: vi.fn(async () => {}),

35+

trackedTabCleanupMock,

36+

};

37+

});

38+39+

vi.mock("openclaw/plugin-sdk/runtime-env", () => ({

40+

registerUnhandledRejectionHandler: registerUnhandledRejectionHandlerMock,

41+

}));

42+43+

vi.mock("./server-lifecycle.js", () => ({

44+

ensureExtensionRelayForProfiles: ensureExtensionRelayForProfilesMock,

45+

stopKnownBrowserProfiles: stopKnownBrowserProfilesMock,

46+

}));

47+48+

vi.mock("./session-tab-cleanup.js", () => ({

49+

startTrackedBrowserTabCleanupTimer: startTrackedBrowserTabCleanupTimerMock,

50+

}));

51+52+

vi.mock("./pw-ai-state.js", () => ({

53+

isPwAiLoaded: isPwAiLoadedMock,

54+

}));

55+56+

vi.mock("./pw-ai-module.js", () => ({

57+

getPwAiModule: getPwAiModuleMock,

58+

}));

59+60+

const { createBrowserRuntimeState, stopBrowserRuntime } = await import("./runtime-lifecycle.js");

61+

const { isPlaywrightDialogRaceUnhandledRejection } = await import("./unhandled-rejections.js");

62+63+

beforeEach(() => {

64+

resetHandlers();

65+

registerUnhandledRejectionHandlerMock.mockClear();

66+

ensureExtensionRelayForProfilesMock.mockClear();

67+

getPwAiModuleMock.mockClear();

68+

isPwAiLoadedMock.mockReset().mockReturnValue(false);

69+

startTrackedBrowserTabCleanupTimerMock.mockClear();

70+

stopKnownBrowserProfilesMock.mockClear();

71+

trackedTabCleanupMock.mockClear();

72+

});

73+74+

describe("browser unhandled rejection lifecycle", () => {

75+

it("matches direct and nested Playwright dialog-race protocol errors", () => {

76+

const direct = Object.assign(

77+

new Error("Protocol error (Page.handleJavaScriptDialog): No dialog is showing"),

78+

{ method: "Page.handleJavaScriptDialog" },

79+

);

80+

const nested = new Error("browser action failed", {

81+

cause: Object.assign(new Error("No dialog is showing"), {

82+

method: "Page.handleJavaScriptDialog",

83+

}),

84+

});

85+

const wrapped = {

86+

error: new Error("Protocol error (Dialog.handleJavaScriptDialog): No dialog is showing"),

87+

};

88+89+

expect(isPlaywrightDialogRaceUnhandledRejection(direct)).toBe(true);

90+

expect(isPlaywrightDialogRaceUnhandledRejection(nested)).toBe(true);

91+

expect(isPlaywrightDialogRaceUnhandledRejection(wrapped)).toBe(true);

92+

});

93+94+

it("keeps non-dialog and non-race Playwright errors unhandled", () => {

95+

expect(

96+

isPlaywrightDialogRaceUnhandledRejection(

97+

Object.assign(new Error("No dialog is showing"), { method: "Page.navigate" }),

98+

),

99+

).toBe(false);

100+

expect(

101+

isPlaywrightDialogRaceUnhandledRejection(

102+

new Error("Protocol error (Page.handleJavaScriptDialog): Target closed"),

103+

),

104+

).toBe(false);

105+

expect(isPlaywrightDialogRaceUnhandledRejection(new Error("No dialog is showing"))).toBe(false);

106+

});

107+108+

it("registers during startup and unregisters during shutdown", async () => {

109+

stopKnownBrowserProfilesMock.mockImplementationOnce(async () => {

110+

expect(getUnhandledRejectionHandlers()).toHaveLength(1);

111+

});

112+

const state = await createBrowserRuntimeState({

113+

resolved: { profiles: {} } as never,

114+

port: 18791,

115+

onWarn: vi.fn(),

116+

});

117+118+

expect(registerUnhandledRejectionHandlerMock).toHaveBeenCalledTimes(1);

119+

expect(getUnhandledRejectionHandlers()).toHaveLength(1);

120+

expect(

121+

getUnhandledRejectionHandlers()[0]?.(

122+

new Error("Protocol error (Page.handleJavaScriptDialog): No dialog is showing"),

123+

),

124+

).toBe(true);

125+126+

const clearState = vi.fn();

127+

await stopBrowserRuntime({

128+

current: state,

129+

getState: () => state,

130+

clearState,

131+

onWarn: vi.fn(),

132+

});

133+134+

expect(trackedTabCleanupMock).toHaveBeenCalledTimes(1);

135+

expect(stopKnownBrowserProfilesMock).toHaveBeenCalledTimes(1);

136+

expect(clearState).toHaveBeenCalledTimes(1);

137+

expect(getUnhandledRejectionHandlers()).toEqual([]);

138+

});

139+

});