Await promises returned from the inPageCallback
This patch teaches puppeteer to await promises returned from the inPageCallback.
This commit is contained in:
parent
ec414eb774
commit
dbffc3c35c
@ -144,7 +144,7 @@ class Page extends EventEmitter {
|
|||||||
var name = inPageCallback.name;
|
var name = inPageCallback.name;
|
||||||
var callback = inPageCallback.callback;
|
var callback = inPageCallback.callback;
|
||||||
var args = await this.evaluate(callbackName => window[callbackName].__args, name);
|
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);
|
await this.evaluate(assignResult, name, result);
|
||||||
this._client.send('Debugger.resume');
|
this._client.send('Debugger.resume');
|
||||||
|
|
||||||
|
10
test/test.js
10
test/test.js
@ -73,6 +73,16 @@ describe('Puppeteer', function() {
|
|||||||
});
|
});
|
||||||
expect(result).toBe(36);
|
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);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user