Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: unrelease 'fonts' screenshot option (#13300)

Dmitry Gozmana09b8dfa3628
diff --git a/docs/src/api/params.md b/docs/src/api/params.md
index 14346d79c9..738bbc74c0 100644
--- a/docs/src/api/params.md
+++ b/docs/src/api/params.md
@@ -975,7 +975,6 @@ When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`,
- %%-screenshot-option-quality-%%
- %%-screenshot-option-path-%%
- %%-screenshot-option-scale-%%
-- %%-screenshot-option-fonts-%%
- %%-screenshot-option-caret-%%
- %%-screenshot-option-type-%%
- %%-screenshot-option-mask-%%
diff --git a/packages/playwright-core/src/client/elementHandle.ts b/packages/playwright-core/src/client/elementHandle.ts
index 61f81b59f6..82ba3c62bb 100644
--- a/packages/playwright-core/src/client/elementHandle.ts
+++ b/packages/playwright-core/src/client/elementHandle.ts
@@ -200,6 +200,7 @@ export class ElementHandle<T extends Node = Node> extends JSHandle<T> implements
selector: locator._selector,
}));
}
+ copy.fonts = (options as any)._fonts;
const result = await this._elementChannel.screenshot(copy);
const buffer = Buffer.from(result.binary, 'base64');
if (options.path) {
diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts
index 4634dd6134..fde819af87 100644
--- a/packages/playwright-core/src/client/page.ts
+++ b/packages/playwright-core/src/client/page.ts
@@ -489,6 +489,7 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
selector: locator._selector,
}));
}
+ copy.fonts = (options as any)._fonts;
const result = await this._channel.screenshot(copy);
const buffer = Buffer.from(result.binary, 'base64');
if (options.path) {
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index 8a53bbd039..8344ff26ea 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -8154,13 +8154,6 @@ export interface ElementHandle<T=Node> extends JSHandle<T> {
*/
caret?: "hide"|"initial";
- /**
- * When set to `"ready"`, screenshot will wait for
- * [`document.fonts.ready`](https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet/ready) promise to resolve in all
- * frames. Defaults to `"nowait"`.
- */
- fonts?: "ready"|"nowait";
-
/**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlayed with a pink box
* `#FF00FF` that completely covers its bounding box.
@@ -15748,13 +15741,6 @@ export interface LocatorScreenshotOptions {
*/
caret?: "hide"|"initial";
- /**
- * When set to `"ready"`, screenshot will wait for
- * [`document.fonts.ready`](https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet/ready) promise to resolve in all
- * frames. Defaults to `"nowait"`.
- */
- fonts?: "ready"|"nowait";
-
/**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlayed with a pink box
* `#FF00FF` that completely covers its bounding box.
@@ -15932,13 +15918,6 @@ export interface PageScreenshotOptions {
height: number;
};
- /**
- * When set to `"ready"`, screenshot will wait for
- * [`document.fonts.ready`](https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet/ready) promise to resolve in all
- * frames. Defaults to `"nowait"`.
- */
- fonts?: "ready"|"nowait";
-
/**
* When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to
* `false`.
diff --git a/packages/playwright-test/src/matchers/toMatchSnapshot.ts b/packages/playwright-test/src/matchers/toMatchSnapshot.ts
index 4f61157cba..e7b525341c 100644
--- a/packages/playwright-test/src/matchers/toMatchSnapshot.ts
+++ b/packages/playwright-test/src/matchers/toMatchSnapshot.ts
@@ -310,7 +310,7 @@ export async function toHaveScreenshot(
const [page, locator] = pageOrLocator.constructor.name === 'Page' ? [(pageOrLocator as PageEx), undefined] : [(pageOrLocator as Locator).page() as PageEx, pageOrLocator as LocatorEx];
const screenshotOptions = {
animations: config?.animations ?? 'disabled',
- fonts: config?.fonts ?? 'ready',
+ _fonts: config?.fonts ?? 'ready',
scale: config?.scale ?? 'css',
caret: config?.caret ?? 'hide',
...helper.allOptions,
diff --git a/tests/page/page-screenshot.spec.ts b/tests/page/page-screenshot.spec.ts
index 3e5c9d327e..9e1ac49554 100644
--- a/tests/page/page-screenshot.spec.ts
+++ b/tests/page/page-screenshot.spec.ts
@@ -785,13 +785,13 @@ it.describe('page screenshot animations', () => {
const noIconsScreenshot = await page.screenshot();
// Make sure screenshot times out while webfont is stalled.
const error = await page.screenshot({
- fonts: 'ready',
+ _fonts: 'ready',
timeout: 200,
- }).catch(e => e);
+ } as any).catch(e => e);
expect(error.message).toContain('waiting for fonts to load...');
expect(error.message).toContain('Timeout 200ms exceeded');
const [iconsScreenshot] = await Promise.all([
- page.screenshot({ fonts: 'ready' }),
+ page.screenshot({ _fonts: 'ready' } as any),
server.serveFile(serverRequest, serverResponse),
]);
expect(iconsScreenshot).toMatchSnapshot('screenshot-web-font.png', {
diff --git a/tests/playwright-test/to-have-screenshot.spec.ts b/tests/playwright-test/to-have-screenshot.spec.ts
index bbfe50362b..69e3d4aef6 100644
--- a/tests/playwright-test/to-have-screenshot.spec.ts
+++ b/tests/playwright-test/to-have-screenshot.spec.ts
@@ -369,7 +369,8 @@ test('should compile with different option combinations', async ({ runTSC }) =>
maxDiffPixelRatio: 0.2,
animations: "disabled",
omitBackground: true,
- fonts: "nowait",
+ // TODO: uncomment when enabling "fonts".
+ // fonts: "nowait",
caret: "initial",
scale: "device",
timeout: 1000,