From 5baae86e2320247ef3904fa25f6fdcefb1694fb2 Mon Sep 17 00:00:00 2001 From: Oliver Switzer Date: Sun, 6 Feb 2022 22:34:08 -0500 Subject: [PATCH] Adds better typing for connect_over_cdp/3 --- lib/playwright/browser_type.ex | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/playwright/browser_type.ex b/lib/playwright/browser_type.ex index c45475ef..107cd790 100644 --- a/lib/playwright/browser_type.ex +++ b/lib/playwright/browser_type.ex @@ -35,7 +35,12 @@ defmodule Playwright.BrowserType do @type client :: :chromium | :firefox | :webkit @typedoc "Options for `connect/2`" - @type connect_options :: map() + @type connect_options :: %{ + optional(:headers) => map(), + optional(:slow_mo) => integer(), + optional(:timeout) => integer() + } + @type connect_over_cdp_options :: connect_options() @typedoc "A map/struct providing call options" @type options :: map() @@ -55,12 +60,12 @@ defmodule Playwright.BrowserType do ## Arguments - | key/name | type | | description | + | key/name | type | | description | | ------------- | ------ | --------------------------- | ----------- | | `ws_endpoint` | param | `BrowserType.ws_endpoint()` | A browser websocket endpoint to connect to. | | `:headers` | option | `map()` | Additional HTTP headers to be sent with websocket connect request | - | `:slow_mow` | option | `integer()` | Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. `(default: 0)` | - | `:logger` | option | | Logger sink for Playwright logging | + | `:slow_mo` | option | `integer()` | Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. `(default: 0)` | + | `:logger` | N/A | NOT IMPLEMENTED YET | Logger sink for Playwright logging | | `:timeout` | option | `integer()` | Maximum time in milliseconds to wait for the connection to be established. Pass `0` to disable timeout. `(default: 30_000 (30 seconds))` | """ @spec connect(ws_endpoint(), connect_options()) :: {pid(), Playwright.Browser.t()} @@ -77,13 +82,11 @@ defmodule Playwright.BrowserType do end end - # --- - # IMPORTANT: `Browser` instances returned from `connect_over_cdp` are effectively pointers # to existing Chromium devtools sessions. That is, our `Catalog` will contain, for example, # multiple `Page` instances pointing to the same Playwright server browser session. # Or... something like that. - @spec connect_over_cdp(Playwright.Browser.t(), url(), options()) :: Playwright.Browser.t() + @spec connect_over_cdp(Playwright.Browser.t(), url(), connect_over_cdp_options()) :: Playwright.Browser.t() def connect_over_cdp(%Playwright.Browser{} = browser, endpoint_url, options \\ %{}) do params = %{