diff --git a/lib/Page.js b/lib/Page.js index 9511e191f2e..e85673ca4ac 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -144,7 +144,7 @@ class Page extends EventEmitter { var name = inPageCallback.name; var callback = inPageCallback.callback; var args = await this.evaluate(callbackName => window[callbackName].__args, name); - var result = callback.apply(null, args); + var result = await Promise.resolve(callback.apply(null, args)); await this.evaluate(assignResult, name, result); this._client.send('Debugger.resume'); diff --git a/test/test.js b/test/test.js index 283906fa87d..a533065594b 100644 --- a/test/test.js +++ b/test/test.js @@ -73,6 +73,16 @@ describe('Puppeteer', function() { }); expect(result).toBe(36); })); + it('should await returned promise', SX(async function() { + await page.setInPageCallback('callController', function(a, b) { + return Promise.resolve(a * b); + }); + + var result = await page.evaluate(function() { + return callController(3, 5); + }); + expect(result).toBe(15); + })); }); });