Await promises returned from the inPageCallback

This patch teaches puppeteer to await promises returned
from the inPageCallback.
This commit is contained in:
Andrey Lushnikov 2017-06-14 08:21:56 -07:00
parent ec414eb774
commit dbffc3c35c
2 changed files with 11 additions and 1 deletions

View File

@ -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');

View File

@ -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);
}));
});
});