fix: ignore spurious bindingCalled events (#6538)

This commit is contained in:
Johan Bay 2020-10-23 12:45:47 +02:00 committed by GitHub
parent e6b8c77d94
commit 5e5fed1deb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -537,7 +537,15 @@ export class DOMWorld {
private async _onBindingCalled(
event: Protocol.Runtime.BindingCalledEvent
): Promise<void> {
const { type, name, seq, args } = JSON.parse(event.payload);
let payload: { type: string; name: string; seq: number; args: unknown[] };
try {
payload = JSON.parse(event.payload);
} catch {
// The binding was either called by something in the page or it was
// called before our wrapper was initialized.
return;
}
const { type, name, seq, args } = payload;
if (type !== 'internal' || !this._ctxBindings.has(name)) return;
if (!this._hasContext()) return;
const context = await this.executionContext();

View File

@ -1132,7 +1132,15 @@ export class Page extends EventEmitter {
private async _onBindingCalled(
event: Protocol.Runtime.BindingCalledEvent
): Promise<void> {
const { type, name, seq, args } = JSON.parse(event.payload);
let payload: { type: string; name: string; seq: number; args: unknown[] };
try {
payload = JSON.parse(event.payload);
} catch {
// The binding was either called by something in the page or it was
// called before our wrapper was initialized.
return;
}
const { type, name, seq, args } = payload;
if (type !== 'exposedFun' || !this._pageBindings.has(name)) return;
let expression = null;
try {