Skip to content

Commit

Permalink
Adds better typing for connect_over_cdp/3
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Switzer committed Feb 7, 2022
1 parent 60960dd commit 5baae86
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/playwright/browser_type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()}
Expand All @@ -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 =
%{
Expand Down

0 comments on commit 5baae86

Please sign in to comment.