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, contextId: number,
session: CDPSession = this.#client session: CDPSession = this.#client
): ExecutionContext { ): ExecutionContext {
const key = `${session.id()}:${contextId}`; const context = this.getExecutionContextById(contextId, session);
const context = this.#contextIdToContext.get(key);
assert(context, 'INTERNAL ERROR: missing context with id = ' + contextId); assert(context, 'INTERNAL ERROR: missing context with id = ' + contextId);
return context; return context;
} }
getExecutionContextById(
contextId: number,
session: CDPSession = this.#client
): ExecutionContext | undefined {
return this.#contextIdToContext.get(`${session.id()}:${contextId}`);
}
page(): Page { page(): Page {
return this.#page; return this.#page;
} }

View File

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