Skip to content

Commit

Permalink
fix: wait for fonts before pdf printing (#12175)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Apr 2, 2024
1 parent f332284 commit 59bffce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/puppeteer-core/src/bidi/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ export class BidiPage extends Page {
preferCSSPageSize,
} = parsePDFOptions(options, 'cm');
const pageRanges = ranges ? ranges.split(', ') : [];

await firstValueFrom(
from(
this.mainFrame()
.isolatedRealm()
.evaluate(() => {
return document.fonts.ready;
})
).pipe(raceWith(timeout(ms)))
);

const data = await firstValueFrom(
from(
this.#frame.browsingContext.print({
Expand Down
10 changes: 10 additions & 0 deletions packages/puppeteer-core/src/cdp/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,16 @@ export class CdpPage extends Page {
await this.#emulationManager.setTransparentBackgroundColor();
}

await firstValueFrom(
from(
this.mainFrame()
.isolatedRealm()
.evaluate(() => {
return document.fonts.ready;
})
).pipe(raceWith(timeout(ms)))
);

const printCommandPromise = this.#primaryTargetClient.send(
'Page.printToPDF',
{
Expand Down

0 comments on commit 59bffce

Please sign in to comment.