Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: evaluate in utility for screenshots (#6364)
Dmitry Gozman263a0fd2e183
diff --git a/src/server/firefox/ffPage.ts b/src/server/firefox/ffPage.tsindex 523f910355..1f69fce1c0 100644--- a/src/server/firefox/ffPage.ts+++ b/src/server/firefox/ffPage.ts@@ -398,7 +398,7 @@ export class FFPage implements PageDelegate {async takeScreenshot(progress: Progress, format: 'png' | 'jpeg', documentRect: types.Rect | undefined, viewportRect: types.Rect | undefined, quality: number | undefined): Promise<Buffer> {if (!documentRect) {- const scrollOffset = await this._page.mainFrame().waitForFunctionValue(progress, () => ({ x: window.scrollX, y: window.scrollY }));+ const scrollOffset = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => ({ x: window.scrollX, y: window.scrollY }));documentRect = {x: viewportRect!.x + scrollOffset.x,y: viewportRect!.y + scrollOffset.y,diff --git a/src/server/frames.ts b/src/server/frames.tsindex 65e7cbfed6..00b19d69dc 100644--- a/src/server/frames.ts+++ b/src/server/frames.ts@@ -1092,7 +1092,7 @@ export class Frame extends SdkObject {}, this._page._timeoutSettings.timeout(options));}- async _waitForFunctionExpression<R>(metadata: CallMetadata, expression: string, isFunction: boolean | undefined, arg: any, options: types.WaitForFunctionOptions = {}): Promise<js.SmartHandle<R>> {+ async _waitForFunctionExpression<R>(metadata: CallMetadata, expression: string, isFunction: boolean | undefined, arg: any, options: types.WaitForFunctionOptions, world: types.World = 'main'): Promise<js.SmartHandle<R>> {const controller = new ProgressController(metadata, this);if (typeof options.pollingInterval === 'number')assert(options.pollingInterval > 0, 'Cannot poll with non-positive interval: ' + options.pollingInterval);@@ -1116,19 +1116,18 @@ export class Frame extends SdkObject {return injectedScript.pollInterval(polling, (progress, continuePolling) => predicate(arg) || continuePolling);}, { expression, isFunction, polling: options.pollingInterval, arg });return controller.run(- progress => this._scheduleRerunnableHandleTask(progress, 'main', task),+ progress => this._scheduleRerunnableHandleTask(progress, world, task),this._page._timeoutSettings.timeout(options));}- async waitForFunctionValue<R>(progress: Progress, pageFunction: js.Func1<any, R>) {+ async waitForFunctionValueInUtility<R>(progress: Progress, pageFunction: js.Func1<any, R>) {const expression = `() => {const result = (${pageFunction})();if (!result)return result;return JSON.stringify(result);-}`;- const handle = await this._page.mainFrame()._waitForFunctionExpression(internalCallMetadata(), expression, true, undefined, { timeout: progress.timeUntilDeadline() });+ const handle = await this._waitForFunctionExpression(internalCallMetadata(), expression, true, undefined, { timeout: progress.timeUntilDeadline() }, 'utility');return JSON.parse(handle.rawValue()) as R;}diff --git a/src/server/injected/selectorEvaluator.ts b/src/server/injected/selectorEvaluator.tsindex 3be98f3368..fd873cb665 100644--- a/src/server/injected/selectorEvaluator.ts+++ b/src/server/injected/selectorEvaluator.ts@@ -73,7 +73,7 @@ export class SelectorEvaluatorImpl implements SelectorEvaluator {const parserNames = Array.from(customCSSNames).slice();parserNames.sort();if (allNames.join('|') !== parserNames.join('|'))- throw new Error(`Please keep customCSSNames in sync with evaluator engines`);+ throw new Error(`Please keep customCSSNames in sync with evaluator engines: ${allNames.join('|')} vs ${parserNames.join('|')}`);}begin() {diff --git a/src/server/screenshotter.ts b/src/server/screenshotter.tsindex 4d3f2a9c88..dfe4b8e995 100644--- a/src/server/screenshotter.ts+++ b/src/server/screenshotter.ts@@ -35,12 +35,12 @@ export class Screenshotter {const originalViewportSize = this._page.viewportSize();let viewportSize = originalViewportSize;if (!viewportSize)- viewportSize = await this._page.mainFrame().waitForFunctionValue(progress, () => ({ width: window.innerWidth, height: window.innerHeight }));+ viewportSize = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => ({ width: window.innerWidth, height: window.innerHeight }));return { viewportSize, originalViewportSize };}private async _fullPageSize(progress: Progress): Promise<types.Size> {- const fullPageSize = await this._page.mainFrame().waitForFunctionValue(progress, () => {+ const fullPageSize = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => {if (!document.body || !document.documentElement)return null;return {@@ -122,7 +122,7 @@ export class Screenshotter {}progress.throwIfAborted(); // Avoid extra work.- const scrollOffset = await this._page.mainFrame().waitForFunctionValue(progress, () => ({ x: window.scrollX, y: window.scrollY }));+ const scrollOffset = await this._page.mainFrame().waitForFunctionValueInUtility(progress, () => ({ x: window.scrollX, y: window.scrollY }));const documentRect = { ...boundingBox };documentRect.x += scrollOffset.x;documentRect.y += scrollOffset.y;diff --git a/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/chromium/screenshot-grid-fullpage.png b/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/chromium/screenshot-grid-fullpage.pngnew file mode 100644index 0000000000..0354694da1Binary files /dev/null and b/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/chromium/screenshot-grid-fullpage.png differdiff --git a/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/firefox/screenshot-grid-fullpage.png b/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/firefox/screenshot-grid-fullpage.pngnew file mode 100644index 0000000000..e87220e057Binary files /dev/null and b/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/firefox/screenshot-grid-fullpage.png differdiff --git a/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/webkit/screenshot-grid-fullpage.png b/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/webkit/screenshot-grid-fullpage.pngnew file mode 100644index 0000000000..8f12800e5cBinary files /dev/null and b/tests/__snapshots__/page-screenshot/should-work-with-Array-deleted/webkit/screenshot-grid-fullpage.png differdiff --git a/tests/page-screenshot.spec.ts b/tests/page-screenshot.spec.tsindex d60f1c01b4..1306807259 100644--- a/tests/page-screenshot.spec.ts+++ b/tests/page-screenshot.spec.ts@@ -268,6 +268,14 @@ it.describe('page screenshot', () => {await page.screenshot();expect(resizeTriggered).toBeFalsy();});++ it('should work with Array deleted', async ({page, server}) => {+ await page.setViewportSize({width: 500, height: 500});+ await page.goto(server.PREFIX + '/grid.html');+ await page.evaluate(() => delete window.Array);+ const screenshot = await page.screenshot({ fullPage: true });+ expect(screenshot).toMatchSnapshot('screenshot-grid-fullpage.png');+ });});browserTest.describe('page screenshot', () => {