Skip to content

StaticImageExport: Allow to use a local browser, instead of BrowserFetcher #264

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

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/Plotly.NET.ImageExport/PuppeteerSharpRenderer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ open DynamicObj
module PuppeteerSharpRendererOptions =

let mutable launchOptions = LaunchOptions()

launchOptions.Timeout <- 60000

let mutable localBrowserExecutablePath = None


type PuppeteerSharpRenderer() =

/// adapted from the original C# implementation by @ilyalatt : https://github.com/ilyalatt/Plotly.NET.PuppeteerRenderer
Expand Down Expand Up @@ -78,16 +80,25 @@ type PuppeteerSharpRenderer() =
/// Initalizes headless browser
let fetchAndLaunchBrowserAsync () =
async {
use browserFetcher = new BrowserFetcher()
match PuppeteerSharpRendererOptions.localBrowserExecutablePath with
| None ->
use browserFetcher = new BrowserFetcher()

let! revision = browserFetcher.DownloadAsync() |> Async.AwaitTask
let! revision = browserFetcher.DownloadAsync() |> Async.AwaitTask

let launchOptions =
PuppeteerSharpRendererOptions.launchOptions
let launchOptions =
PuppeteerSharpRendererOptions.launchOptions

launchOptions.ExecutablePath <- revision.ExecutablePath
launchOptions.ExecutablePath <- revision.ExecutablePath

return! Puppeteer.LaunchAsync(launchOptions) |> Async.AwaitTask
return! Puppeteer.LaunchAsync(launchOptions) |> Async.AwaitTask
| Some p ->
let launchOptions =
PuppeteerSharpRendererOptions.launchOptions

launchOptions.ExecutablePath <- p

return! Puppeteer.LaunchAsync(launchOptions) |> Async.AwaitTask
}

/// Initalizes headless browser
Expand Down