fix: `exposeBinding` should work in parallel
This commit is contained in:
parent
30ddf7ad6b
commit
dc209d2e7a
|
|
@ -93,7 +93,7 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
_closeReason: string | undefined;
|
_closeReason: string | undefined;
|
||||||
readonly clock: Clock;
|
readonly clock: Clock;
|
||||||
_clientCertificatesProxy: ClientCertificatesProxy | undefined;
|
_clientCertificatesProxy: ClientCertificatesProxy | undefined;
|
||||||
private _playwrightBindingExposed = false;
|
private _playwrightBindingExposed?: Promise<void>;
|
||||||
readonly dialogManager: DialogManager;
|
readonly dialogManager: DialogManager;
|
||||||
|
|
||||||
constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) {
|
constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) {
|
||||||
|
|
@ -304,19 +304,19 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
async exposePlaywrightBindingIfNeeded() {
|
async exposePlaywrightBindingIfNeeded() {
|
||||||
if (this._playwrightBindingExposed)
|
this._playwrightBindingExposed ??= (async () => {
|
||||||
return;
|
await this.doExposePlaywrightBinding();
|
||||||
this._playwrightBindingExposed = true;
|
|
||||||
await this.doExposePlaywrightBinding();
|
|
||||||
|
|
||||||
this.bindingsInitScript = PageBinding.createInitScript();
|
this.bindingsInitScript = PageBinding.createInitScript();
|
||||||
this.initScripts.push(this.bindingsInitScript);
|
this.initScripts.push(this.bindingsInitScript);
|
||||||
await this.doAddInitScript(this.bindingsInitScript);
|
await this.doAddInitScript(this.bindingsInitScript);
|
||||||
await this.safeNonStallingEvaluateInAllFrames(this.bindingsInitScript.source, 'main');
|
await this.safeNonStallingEvaluateInAllFrames(this.bindingsInitScript.source, 'main');
|
||||||
|
})();
|
||||||
|
return await this._playwrightBindingExposed;
|
||||||
}
|
}
|
||||||
|
|
||||||
needsPlaywrightBinding() {
|
needsPlaywrightBinding(): boolean {
|
||||||
return this._playwrightBindingExposed;
|
return this._playwrightBindingExposed !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async exposeBinding(progress: Progress, name: string, needsHandle: boolean, playwrightBinding: frames.FunctionWithSource, forClient?: unknown): Promise<PageBinding> {
|
async exposeBinding(progress: Progress, name: string, needsHandle: boolean, playwrightBinding: frames.FunctionWithSource, forClient?: unknown): Promise<PageBinding> {
|
||||||
|
|
|
||||||
|
|
@ -292,3 +292,14 @@ it('should fail with busted Array.prototype.toJSON', async ({ page }) => {
|
||||||
|
|
||||||
expect.soft(await page.evaluate(() => ([] as any).toJSON())).toBe('"[]"');
|
expect.soft(await page.evaluate(() => ([] as any).toJSON())).toBe('"[]"');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('exposeBinding should work in parallel', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37712' } }, async ({ page }) => {
|
||||||
|
await Promise.all([
|
||||||
|
page.exposeBinding('foo', () => 42),
|
||||||
|
page.exposeBinding('bar', () => 42),
|
||||||
|
]);
|
||||||
|
await page.evaluate(() => {
|
||||||
|
(window as any).foo();
|
||||||
|
(window as any).bar();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue