From c30d88a63a25acf75bff5b0d87fc7b45cc698169 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 9 Mar 2023 10:45:19 -0800 Subject: [PATCH] test: setContent with disabled javascript (#21399) Fixes https://github.com/microsoft/playwright/issues/21379 --- packages/playwright-core/src/server/webkit/wkPage.ts | 3 ++- tests/library/browsercontext-basic.spec.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts index 74fea4617f..d47292373e 100644 --- a/packages/playwright-core/src/server/webkit/wkPage.ts +++ b/packages/playwright-core/src/server/webkit/wkPage.ts @@ -570,7 +570,8 @@ export class WKPage implements PageDelegate { const objectId = JSON.parse(p.objectId); context = this._contextIdToContext.get(objectId.injectedScriptId); } else { - context = this._contextIdToContext.get(this._mainFrameContextId!); + // Pick any context if the parameter is a value. + context = [...this._contextIdToContext.values()].find(c => c.frame === this._page.mainFrame()); } if (!context) return; diff --git a/tests/library/browsercontext-basic.spec.ts b/tests/library/browsercontext-basic.spec.ts index e0b74be625..373eb954a1 100644 --- a/tests/library/browsercontext-basic.spec.ts +++ b/tests/library/browsercontext-basic.spec.ts @@ -223,6 +223,14 @@ it('should not hang on promises after disabling javascript', async ({ browserNam expect(await page.evaluate(async () => 2)).toBe(2); }); +it('setContent should work after disabling javascript', async ({ contextFactory, browserName, isLinux }) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/18235' }); + const context = await contextFactory({ javaScriptEnabled: false }); + const page = await context.newPage(); + await page.setContent('

Hello

'); + await expect(page.locator('h1')).toHaveText('Hello'); +}); + it('should work with offline option', async ({ browser, server }) => { const context = await browser.newContext({ offline: true }); const page = await context.newPage();