diff --git a/lib/FrameManager.js b/lib/FrameManager.js index b187a393..3a79b763 100644 --- a/lib/FrameManager.js +++ b/lib/FrameManager.js @@ -836,8 +836,10 @@ class WaitTask { }); // Since page navigation requires us to re-install the pageScript, we should track // timeout on our end. - if (timeout) - this._timeoutTimer = setTimeout(() => this.terminate(new Error(`waiting for ${title} failed: timeout ${timeout}ms exceeded`)), timeout); + if (timeout) { + const timeoutError = new Error(`waiting for ${title} failed: timeout ${timeout}ms exceeded`); + this._timeoutTimer = setTimeout(() => this.terminate(timeoutError), timeout); + } this.rerun(); } diff --git a/test/frame.spec.js b/test/frame.spec.js index ae2a325d..4b05c6a1 100644 --- a/test/frame.spec.js +++ b/test/frame.spec.js @@ -332,6 +332,11 @@ module.exports.addTests = function({testRunner, expect}) { await page.setContent(`
anything
`); expect(await page.evaluate(x => x.textContent, await waitForSelector)).toBe('anything'); }); + it('should have correct stack trace for timeout', async({page, server}) => { + let error; + await page.waitForSelector('.zombo', {timeout: 10}).catch(e => error = e); + expect(error.stack).toContain('frame.spec.js'); + }); }); describe('Frame.waitForXPath', function() {