fix: ignore not found contexts for console messages (#9595)

This commit is contained in:
Alex Rudenko 2023-01-30 11:22:55 +01:00 committed by GitHub
parent 6f094d2f83
commit 390685bbe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -174,12 +174,18 @@ export class FrameManager extends EventEmitter {
contextId: number,
session: CDPSession = this.#client
): ExecutionContext {
const key = `${session.id()}:${contextId}`;
const context = this.#contextIdToContext.get(key);
const context = this.getExecutionContextById(contextId, session);
assert(context, 'INTERNAL ERROR: missing context with id = ' + contextId);
return context;
}
getExecutionContextById(
contextId: number,
session: CDPSession = this.#client
): ExecutionContext | undefined {
return this.#contextIdToContext.get(`${session.id()}:${contextId}`);
}
page(): Page {
return this.#page;
}

View File

@ -747,10 +747,20 @@ export class CDPPage extends Page {
// @see https://github.com/puppeteer/puppeteer/issues/3865
return;
}
const context = this.#frameManager.executionContextById(
const context = this.#frameManager.getExecutionContextById(
event.executionContextId,
this.#client
);
if (!context) {
debugError(
new Error(
`ExecutionContext not found for a console message: ${JSON.stringify(
event
)}`
)
);
return;
}
const values = event.args.map(arg => {
return createJSHandle(context, arg);
});