fix: wait for fonts before pdf printing (#12175)

This commit is contained in:
Alex Rudenko 2024-04-02 10:52:51 +02:00 committed by GitHub
parent f332284ffc
commit 59bffce972
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -321,6 +321,17 @@ export class BidiPage extends Page {
preferCSSPageSize, preferCSSPageSize,
} = parsePDFOptions(options, 'cm'); } = parsePDFOptions(options, 'cm');
const pageRanges = ranges ? ranges.split(', ') : []; const pageRanges = ranges ? ranges.split(', ') : [];
await firstValueFrom(
from(
this.mainFrame()
.isolatedRealm()
.evaluate(() => {
return document.fonts.ready;
})
).pipe(raceWith(timeout(ms)))
);
const data = await firstValueFrom( const data = await firstValueFrom(
from( from(
this.#frame.browsingContext.print({ this.#frame.browsingContext.print({

View File

@ -1133,6 +1133,16 @@ export class CdpPage extends Page {
await this.#emulationManager.setTransparentBackgroundColor(); await this.#emulationManager.setTransparentBackgroundColor();
} }
await firstValueFrom(
from(
this.mainFrame()
.isolatedRealm()
.evaluate(() => {
return document.fonts.ready;
})
).pipe(raceWith(timeout(ms)))
);
const printCommandPromise = this.#primaryTargetClient.send( const printCommandPromise = this.#primaryTargetClient.send(
'Page.printToPDF', 'Page.printToPDF',
{ {