Last active
December 9, 2018 19:26
-
-
Save baronfel/5667a97c0d62fbf98a7787156ab677b1 to your computer and use it in GitHub Desktop.
Snippets for my F# Advent 2018 blogpost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install the latest version of the template | |
dotnet new -i "MiniScaffold::*" | |
# create a new project with the template | |
dotnet new mini-scaffold -n Figurine --githubUsername baronfel -lang F# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Types = | |
type BrowserCtx = | |
{ /// the actual unit of work | |
page : Page | |
dispose : unit -> unit | |
compareTimeout : System.TimeSpan | |
navigateTimeout : System.TimeSpan } | |
member x.CurrentUrl = x.page.Url | |
interface IDisposable with | |
member x.Dispose() = x.dispose() | |
module Browser = | |
open Types | |
type LaunchMethod = | |
| Launch of LaunchOptions | |
| Connect of ConnectOptions | |
let create (method : LaunchMethod) = | |
let factory = | |
match method with | |
| Launch opts -> Puppeteer.LaunchAsync opts | |
| Connect opts -> Puppeteer.ConnectAsync opts | |
let b = Task.force factory | |
let p = b.NewPageAsync() |> Task.force | |
{ page = p | |
dispose = b.Dispose | |
compareTimeout = TimeSpan.FromSeconds 10. | |
navigateTimeout = TimeSpan.FromSeconds 30. } | |
let createFromExe (path : string) = | |
create (Launch(LaunchOptions(ExecutablePath = path))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment