chore: introduce minimal viewport for WebKit/Windows/headed (#22956)

Fixes https://github.com/microsoft/playwright/issues/22616
This commit is contained in:
Max Schmitt 2023-05-11 17:54:05 +02:00 committed by GitHub
parent a2bfbd9a0f
commit 00187172f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 2 deletions

View file

@ -212,6 +212,7 @@ export class WKBrowserContext extends BrowserContext {
constructor(browser: WKBrowser, browserContextId: string | undefined, options: channels.BrowserNewContextParams) {
super(browser, options, browserContextId);
this._validateEmulatedViewport(options.viewport);
this._authenticateProxyViaHeader();
}
@ -361,4 +362,11 @@ export class WKBrowserContext extends BrowserContext {
async cancelDownload(uuid: string) {
await this._browser._browserSession.send('Playwright.cancelDownload', { uuid });
}
_validateEmulatedViewport(viewportSize?: types.Size | null) {
if (!viewportSize)
return;
if (process.platform === 'win32' && this._browser.options.headful && (viewportSize.width < 250 || viewportSize.height < 250))
throw new Error(`WebKit on Windows has a minimal viewport of 250x250.`);
}
}

View file

@ -681,6 +681,7 @@ export class WKPage implements PageDelegate {
}
async updateEmulatedViewportSize(): Promise<void> {
this._browserContext._validateEmulatedViewport(this._page.viewportSize());
await this._updateViewport();
}

View file

@ -150,3 +150,16 @@ browserTest('should drag with high dpi', async ({ browser, server }) => {
expect(await page.$eval('#target', target => target.contains(document.querySelector('#source')))).toBe(true); // could not find source in target
await page.close();
});
it('WebKit Windows headed should have a minimal viewport', async ({ contextFactory, browserName, headless, isWindows }) => {
it.skip(browserName !== 'webkit' || headless || !isWindows, 'Not relevant for this browser');
await expect(contextFactory({
viewport: { 'width': 100, 'height': 100 },
})).rejects.toThrow('WebKit on Windows has a minimal viewport of 250x250.');
const context = await contextFactory();
const page = await context.newPage();
await expect(page.setViewportSize({ width: 100, height: 100 })).rejects.toThrow('WebKit on Windows has a minimal viewport of 250x250.');
await context.close();
});

View file

@ -102,8 +102,8 @@ it('should change document.activeElement', async ({ page, server }) => {
});
it('should not affect screenshots', async ({ page, server, browserName, headless, isWindows }) => {
it.fixme(browserName === 'webkit' && isWindows && !headless, 'https://github.com/microsoft/playwright/issues/22616');
it.skip(browserName === 'firefox' && !headless, 'Firefox headede produces a different image');
it.skip(browserName === 'webkit' && isWindows && !headless, 'WebKit/Windows/headed has a larger minimal viewport. See https://github.com/microsoft/playwright/issues/22616');
it.skip(browserName === 'firefox' && !headless, 'Firefox headed produces a different image');
const page2 = await page.context().newPage();
await Promise.all([