-
Notifications
You must be signed in to change notification settings - Fork 4
fix(core): bound aria-tree frame.evaluate with a timeout to prevent indefinite agent freeze #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+131
−32
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1292,4 +1292,52 @@ describe("PlaywrightBrowser", () => { | |
| await expect(browser.getScreenshot()).rejects.not.toThrow(BrowserDisconnectedError); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getTreeWithRefs frame evaluate timeout", () => { | ||
| let browser: PlaywrightBrowser; | ||
|
|
||
| beforeEach(() => { | ||
| // Tiny per-frame timeout so a non-responsive frame is skipped quickly under | ||
| // real timers (no fake-timer gymnastics around the sequential await loop). | ||
| browser = new PlaywrightBrowser({ browser: "chromium", ariaFrameEvaluateTimeoutMs: 20 }); | ||
| }); | ||
|
|
||
| it("skips a child frame whose evaluate never resolves and still returns the responsive frames", async () => { | ||
| const mainFrame = { evaluate: vi.fn() }; | ||
| // Simulates a hostile/unresponsive ad iframe: evaluate never settles. | ||
| const hangingFrame = { evaluate: vi.fn().mockReturnValue(new Promise(() => {})) }; | ||
| const goodFrame = { | ||
| evaluate: vi.fn().mockResolvedValue({ yaml: "GOOD_FRAME_YAML", counterValue: 5 }), | ||
| }; | ||
| (browser as any).page = { | ||
| evaluate: vi.fn().mockResolvedValue({ yaml: "MAIN_YAML", counterValue: 1 }), | ||
| frames: vi.fn().mockReturnValue([mainFrame, hangingFrame, goodFrame]), | ||
| mainFrame: vi.fn().mockReturnValue(mainFrame), | ||
| }; | ||
|
|
||
| const result = await browser.getTreeWithRefs(); | ||
|
|
||
| expect(result).toContain("MAIN_YAML"); | ||
| expect(result).toContain("GOOD_FRAME_YAML"); | ||
| expect(hangingFrame.evaluate).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("surfaces a main-frame evaluate timeout as an error (not a disconnect)", async () => { | ||
| (browser as any).page = { | ||
| evaluate: vi.fn().mockReturnValue(new Promise(() => {})), // never resolves | ||
| frames: vi.fn().mockReturnValue([]), | ||
| mainFrame: vi.fn(), | ||
| }; | ||
|
|
||
| const error = await browser.getTreeWithRefs().then( | ||
| () => { | ||
| throw new Error("expected getTreeWithRefs to reject"); | ||
| }, | ||
| (e) => e, | ||
| ); | ||
| expect(error).toBeInstanceOf(Error); | ||
| expect((error as Error).message).toMatch(/timed out/i); | ||
| expect(error).not.toBeInstanceOf(BrowserDisconnectedError); | ||
| }); | ||
|
Comment on lines
+1325
to
+1341
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b9f1101 — the test now invokes getTreeWithRefs() once, captures the rejection, and asserts both the /timed out/i message and |
||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in b9f1101 — the option doc now states that a child frame that exceeds the timeout is skipped, while a main-frame timeout surfaces as an error.