Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Allow using Firefox / WebDriver BiDi protocol during conversion #597

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented Sep 24, 2024

Related: #565

Replaces the browser management for converting with new one, implemented in #595. That supports using Firefox, and WebDriver BiDi protocol for Chrome.

This PR will replace only the browser engine. I'm going to work for new options about new browser manager and finders in another pull request.

@yhatt yhatt changed the title Allow using Firefox / WebDriver BiDi protocol during conversion [WIP] Allow using Firefox / WebDriver BiDi protocol during conversion Sep 24, 2024
Copy link
Member Author

@yhatt yhatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memo

})

try {
await page.emulateMediaType('print')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebDriver BiDi does not yet support media type emulation, but it's OK because using bare template, that is almost compatible with the print media, whenever converting to image(s).

Comment on lines +481 to +483
return await sharp()(buf)
.jpeg({ mozjpeg: true, quality: opts.quality })
.toBuffer()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use sharp to convert PNG to JPG because WebDriver Bidi does only support PNG screenshot.

  • ToDo
    • Check compatibility with the standalone binary

this._firefoxPDFConversionWarning = true

warn(
'Using Firefox to convert Markdown to PDF: The output may include some incompatible renderings compared to the PDF generated by Chrome.'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, PDF conversion by Firefox has some incompatible rendeings compared to PDF generated by Chrome. e.g. There are some vanished elements in PDF, such as the background gradient like gaia theme, the element with CSS filter, etc.

➡️ Should treat PDF conversion backed by Firefox as fallback

return await page.screenshot({
clip,
quality: opts.quality,
type: 'jpeg',
omitBackground: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only supported by CDP. WebDriver BiDi will not work #555.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant