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

Add browser options --browser and several sub options #603

Merged
merged 14 commits into from
Oct 3, 2024
Merged

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented Sep 28, 2024

Resolves #565.

This PR introduces new options about browser: --browser, --browser-path, --browser-protocol, and --browser-timeout.

Browser Options:
      --browser           The kind of browser to use for PDF, PPTX, and image
                          conversion
       [string] [choices: "auto", "chrome", "edge", "firefox"] [default: "auto"]
      --browser-path      Path to the browser executable (Find automatically if
                          not set)                                      [string]
      --browser-protocol  Preferred protocol to use for browser connection
                    [string] [choices: "cdp", "webdriver-bidi"] [default: "cdp"]
      --browser-timeout   Timeout for each browser operation in seconds (0 to
                          disable)                                 [default: 30]

--browser

The --browser option specifies the kind of browser for conversion. If set comma-separated browsers, CLI will try to use the first available browser among them.

# Use Firefox for conversion
marp --browser firefox ./slide.md

# Prefer to use Firefox first, then Chrome
marp --browser firefox,chrome ./slide.md

The default value is auto, which means chrome,edge,firefox.

--browser-path

The --browser-path option allows you to explicitly set the path to the browser executable.

# Use the specific Chrome executable
marp --browser-path /usr/bin/google-chrome-stable ./slide.md

# Use the specific Firefox executable
marp --browser firefox --browser-path /usr/bin/firefox ./slide.md

This is similar to setting the CHROME_PATH environment variable in v3 and earlier, but it can be used across all browsers. For backward compatibility, CHROME_PATH is still supported when using chrome as the browser.

--browser-protocol

The --browser-protocol option specifies the preferred protocol to use for browser connection.

# Use WebDriver BiDi protocol in Chrome
marp --browser chrome --browser-protocol webdriver-bidi ./slide.md

The preferred protocol may be ignored if the browser does not support it (e.g. Firefox is only supporting WebDriver BiDi). The default value is cdp (Chrome DevTools Protocol), that is same as up until now.

--browser-timeout

The --browser-timeout option specifies the timeout for each browser operation in seconds. The default timeout is 30 seconds. If set --no-browser-timeout or --browser-timeout=0, the timeout will be disabled.

# Disable timeout
marp --browser-timeout 0 ./slide.md
marp --no-browser-timeout ./slide.md # Equivalent to the above

# Set timeout to 60 seconds
marp --browser-timeout 60 ./slide.md

# Decimal seconds are also supported
marp --browser-timeout 12.34 ./slide.md

# Set timeout in milliseconds
marp --browser-timeout 45000ms ./slide.md

Please note that this timeout is for each browser operation by specified protocol, not for the entire conversion process. For example, opening Marp HTML in browser internally and generating PDF from HTML are separate operations. So if you set --browser-timeout 10, the timeout of 10 seconds are applied to each operation.

@yhatt yhatt merged commit 737e155 into main Oct 3, 2024
1 check passed
@yhatt yhatt deleted the browser-options branch October 3, 2024 15:07
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.

[v4] File conversions using Firefox through WebDriver BiDi
1 participant