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>>;
get puppeteerUtil(): Promise<JSHandle<PuppeteerUtil>> {
scriptInjector.inject(script => {
if (this.#puppeteerUtil) {
this.#puppeteerUtil.then(handle => {
handle.dispose();
});
}
this.#puppeteerUtil = Promise.all([
let promise = Promise.resolve() as Promise<unknown>;
if (!this.#bindingsInstalled) {
promise = Promise.all([
this.#installGlobalBinding(
new Binding(
'__ariaQuerySelector',
@ -111,7 +108,16 @@ export class ExecutionContext {
}, ...(await AsyncIterableUtil.collect(results)));
}) 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>>;
});
}, !this.#puppeteerUtil);