From 972f44d32896aa3e8284f5e793c3f40dc0d62b20 Mon Sep 17 00:00:00 2001 From: JoelEinbinder Date: Mon, 8 Jan 2018 14:14:41 -0800 Subject: [PATCH] fix: avoid calling jsonValue from waitFor (#1746) If the success value of `waitForFunction` was not serializable, checking whether it was truthy with `.jsonValue()` might fail. Now I check whether it was truthy inside the page. Fixes #1737. --- lib/FrameManager.js | 2 +- test/test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/FrameManager.js b/lib/FrameManager.js index 70e2307f..7f635671 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -715,7 +715,7 @@ class WaitTask { } // Ignore timeouts in pageScript - we track timeouts ourselves. - if (!error && !(await success.jsonValue())) { + if (!error && await this._frame.evaluate(s => !s, success)) { await success.dispose(); return; } diff --git a/test/test.js b/test/test.js index 0f7eb4d8..3bd62ff8 100644 --- a/test/test.js +++ b/test/test.js @@ -703,6 +703,9 @@ describe('Page', function() { it('should return the success value as a JSHandle', async({page}) => { expect(await (await page.waitForFunction(() => 5)).jsonValue()).toBe(5); }); + it('should return the window as a success value', async({ page }) => { + expect(await page.waitForFunction(() => window)).toBeTruthy(); + }); it('should accept ElementHandle arguments', async({page}) => { await page.setContent('
'); const div = await page.$('div');