mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor: move disposed handling (#12405)
This commit is contained in:
parent
4937025fb3
commit
93bf52bdfc
@ -490,9 +490,7 @@ export class FrameManager extends EventEmitter<FrameManagerEvents> {
|
||||
contextPayload,
|
||||
world
|
||||
);
|
||||
if (world) {
|
||||
world.setContext(context);
|
||||
}
|
||||
world.setContext(context);
|
||||
const key = `${session.id()}:${contextPayload.id}`;
|
||||
this.#contextIdToContext.set(key, context);
|
||||
context.once('disposed', () => {
|
||||
@ -502,7 +500,6 @@ export class FrameManager extends EventEmitter<FrameManagerEvents> {
|
||||
return;
|
||||
}
|
||||
this.#contextIdToContext.delete(key);
|
||||
context._world.clearContext();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -64,20 +64,19 @@ export class IsolatedWorld extends Realm {
|
||||
return this.#frameOrWorker.client;
|
||||
}
|
||||
|
||||
clearContext(): void {
|
||||
// The message has to match the CDP message expected by the WaitTask class.
|
||||
this.#context?.reject(new Error('Execution context was destroyed'));
|
||||
this.#context = Deferred.create();
|
||||
if ('clearDocumentHandle' in this.#frameOrWorker) {
|
||||
this.#frameOrWorker.clearDocumentHandle();
|
||||
}
|
||||
}
|
||||
|
||||
setContext(context: ExecutionContext): void {
|
||||
const existingContext = this.#context.value();
|
||||
if (existingContext instanceof ExecutionContext) {
|
||||
existingContext[disposeSymbol]();
|
||||
}
|
||||
context.once('disposed', () => {
|
||||
// The message has to match the CDP message expected by the WaitTask class.
|
||||
this.#context?.reject(new Error('Execution context was destroyed'));
|
||||
this.#context = Deferred.create();
|
||||
if ('clearDocumentHandle' in this.#frameOrWorker) {
|
||||
this.#frameOrWorker.clearDocumentHandle();
|
||||
}
|
||||
});
|
||||
this.#context.resolve(context);
|
||||
void this.taskManager.rerunAll();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user