fix: install bindings once (#10049)

This commit is contained in:
jrandolf 2023-04-20 08:59:36 +02:00 committed by GitHub
parent bbf2c0a8ec
commit 690aec1b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,15 +85,12 @@ export class ExecutionContext {
} }
} }
#bindingsInstalled = false;
#puppeteerUtil?: Promise<JSHandle<PuppeteerUtil>>; #puppeteerUtil?: Promise<JSHandle<PuppeteerUtil>>;
get puppeteerUtil(): Promise<JSHandle<PuppeteerUtil>> { get puppeteerUtil(): Promise<JSHandle<PuppeteerUtil>> {
scriptInjector.inject(script => { let promise = Promise.resolve() as Promise<unknown>;
if (this.#puppeteerUtil) { if (!this.#bindingsInstalled) {
this.#puppeteerUtil.then(handle => { promise = Promise.all([
handle.dispose();
});
}
this.#puppeteerUtil = Promise.all([
this.#installGlobalBinding( this.#installGlobalBinding(
new Binding( new Binding(
'__ariaQuerySelector', '__ariaQuerySelector',
@ -111,7 +108,16 @@ export class ExecutionContext {
}, ...(await AsyncIterableUtil.collect(results))); }, ...(await AsyncIterableUtil.collect(results)));
}) as (...args: unknown[]) => unknown) }) as (...args: unknown[]) => unknown)
), ),
]).then(() => { ]);
this.#bindingsInstalled = true;
}
scriptInjector.inject(script => {
if (this.#puppeteerUtil) {
this.#puppeteerUtil.then(handle => {
handle.dispose();
});
}
this.#puppeteerUtil = promise.then(() => {
return this.evaluateHandle(script) as Promise<JSHandle<PuppeteerUtil>>; return this.evaluateHandle(script) as Promise<JSHandle<PuppeteerUtil>>;
}); });
}, !this.#puppeteerUtil); }, !this.#puppeteerUtil);