mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(Connection): do not assert that methods always have callbacks. (#2330)
In certain cases, all callbacks could be rejected before we get a response from transport. This is easily reproducible with `slowMo` option. Fixes #563.
This commit is contained in:
parent
294f33b75c
commit
57fa690724
@ -102,15 +102,17 @@ class Connection extends EventEmitter {
|
|||||||
await new Promise(f => setTimeout(f, this._delay));
|
await new Promise(f => setTimeout(f, this._delay));
|
||||||
debugProtocol('◀ RECV ' + message);
|
debugProtocol('◀ RECV ' + message);
|
||||||
const object = JSON.parse(message);
|
const object = JSON.parse(message);
|
||||||
if (object.id && this._callbacks.has(object.id)) {
|
if (object.id) {
|
||||||
const callback = this._callbacks.get(object.id);
|
const callback = this._callbacks.get(object.id);
|
||||||
this._callbacks.delete(object.id);
|
// Callbacks could be all rejected if someone has called `.dispose()`.
|
||||||
if (object.error)
|
if (callback) {
|
||||||
callback.reject(rewriteError(callback.error, `Protocol error (${callback.method}): ${object.error.message} ${object.error.data}`));
|
this._callbacks.delete(object.id);
|
||||||
else
|
if (object.error)
|
||||||
callback.resolve(object.result);
|
callback.reject(rewriteError(callback.error, `Protocol error (${callback.method}): ${object.error.message} ${object.error.data}`));
|
||||||
|
else
|
||||||
|
callback.resolve(object.result);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.assert(!object.id);
|
|
||||||
if (object.method === 'Target.receivedMessageFromTarget') {
|
if (object.method === 'Target.receivedMessageFromTarget') {
|
||||||
const session = this._sessions.get(object.params.sessionId);
|
const session = this._sessions.get(object.params.sessionId);
|
||||||
if (session)
|
if (session)
|
||||||
|
Loading…
Reference in New Issue
Block a user