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

API redesign: support pipelines #53

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e808632
API: `BrowserContext.add_cookies/2` and `clear_cookies/1` return `sel…
coreyti Jun 5, 2024
694ee22
API: `BrowserContext.on/3` returns `subject()`
coreyti Jun 5, 2024
80e4939
API: `BrowserContext.grant_permissions/3` returns `subject()`
coreyti Jun 5, 2024
ecad471
API: `APIRequestContext` prepare docs/specs
coreyti Jun 5, 2024
e6c556b
API: `BrowserContext.clear_permissions/1` returns `subject()`
coreyti Jun 5, 2024
7e0008b
API: `CDPSession.*` return `subject()`
coreyti Jun 5, 2024
38cef8e
API: `Page.add_init_script/2` returns `subject()`
coreyti Jun 5, 2024
30ef1c3
API: `BrowserContext.add_init_script/2` returns `subject()`
coreyti Jun 5, 2024
40848a3
API: `BrowserContext...` functions return `subject()`
coreyti Jun 5, 2024
6c1e854
API: convert various functions to return `subject()`
coreyti Jun 5, 2024
a399d33
Switch to referring to subject type as t()
ry4n1m3 Aug 12, 2024
6ed3ba6
Split Error types into API and SDK
coreyti Aug 12, 2024
b222442
remove redundant head on ChannelOwner.returning/2
ry4n1m3 Aug 12, 2024
33b6b15
Delete unused UnitTest CaseTemplate
coreyti Aug 12, 2024
e477a3a
API: `BrowserContext.add_cookies/2` and `clear_cookies/1` return `sel…
coreyti Jun 5, 2024
7b9c6b4
API: `BrowserContext.on/3` returns `subject()`
coreyti Jun 5, 2024
958cb06
API: `CDPSession.*` return `subject()`
coreyti Jun 5, 2024
80ca654
API: remove `@deprecated` clause; it's too noisy
coreyti Jun 5, 2024
2aad2ce
API: `BrowserContext...` functions return `subject()`
coreyti Jun 5, 2024
19b9dd1
Remove all `@type subject :: t()`
coreyti Sep 26, 2024
26fed18
SDK: refactor `ChannelOwner.post!/3` -> `Channel.post/3`
coreyti Sep 30, 2024
e920fc7
SDK: add `!` pipelining
coreyti Sep 30, 2024
311608d
Test: match API test FS structure to impl
coreyti Sep 30, 2024
95485d7
API: implement `APIRequest`
coreyti Oct 1, 2024
b248231
Doc: add documentation for `APIRequest`
coreyti Oct 2, 2024
beb1e3e
Fix: clean up module docs
coreyti Oct 2, 2024
c7f5442
API: some `APIRequestContext` & `APIResponse` impl
coreyti Oct 2, 2024
03b39c5
Doc: provide usage for `APIResponse`
coreyti Oct 2, 2024
054781c
API: impl `AIRequestContext.<method>`
coreyti Oct 3, 2024
b534146
API: impl `APIRequestContext.dispose/2`
coreyti Oct 3, 2024
597c3f0
API: impl `APIRequestContext.storage_state/2`
coreyti Oct 3, 2024
e280f58
API: impl `APIRequestContext` & `APIResponse` pipe/bang functions
coreyti Oct 3, 2024
66d0aab
API: add test coverage for `APIResponse`
coreyti Oct 4, 2024
6e2f289
API: impl `APIResponse.headers/1`
coreyti Oct 4, 2024
128799e
Fix: `Catalog.list/2` must filter on Parent GUID
coreyti Oct 6, 2024
6bd1384
Doc: add/fix a number of types, specs, docs
coreyti Oct 6, 2024
2d7a5ac
API: add `options` to `*.close/2`
coreyti Oct 6, 2024
fba8181
API: impl `Browser.browser_type/1`
coreyti Oct 6, 2024
e9f4558
Doc: share opts between `Browser.new_context/2` and `.new_page/2`
coreyti Oct 6, 2024
80b86d5
API: adjust `Browser.new_*` function returns
coreyti Oct 6, 2024
f4c9f7a
API: embrace `Browser.version` as a `@property`
coreyti Oct 6, 2024
acc143f
API: scaffold "tracing"
coreyti Oct 6, 2024
d9a1313
API: add placeholder tests for `Browser.on/3`
coreyti Oct 9, 2024
cb922ce
Fix: return refreshed `Page` from `Browser.new_page/2`
coreyti Oct 9, 2024
ba47c21
API: add pipelining and docs to `Browser` functions
coreyti Oct 9, 2024
b759717
API: fix/improve a number of typespecs and specs
coreyti Oct 9, 2024
cb3881d
API: impl some `BrowserContext` and add tests/docs
coreyti Oct 9, 2024
bbbef41
API: impl `BrowserContext.set_geolocation`
coreyti Oct 9, 2024
d426394
API: impl some `BrowserContext` and fix/clean docs & tests
coreyti Oct 10, 2024
cdf5d07
API: impl `BrowserContext` (un-)routing
coreyti Oct 10, 2024
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
33 changes: 24 additions & 9 deletions lib/playwright.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule Playwright do

alias Playwright.API.{Browser, Page, Response}

{:ok, browser} = Playwright.launch(:chromium)
{:ok, page} = Browser.new_page(browser)
{:ok, session, browser} = Playwright.launch(:chromium)
{:ok, page} = Browser.new_page(browser)
{:ok, response} = Page.goto(browser, "http://example.com")

assert Response.ok(response)
Expand All @@ -18,6 +18,9 @@ defmodule Playwright do
"""

use Playwright.SDK.ChannelOwner
alias Playwright
alias Playwright.APIRequest
alias Playwright.SDK.Channel
alias Playwright.SDK.Config

@property :chromium
Expand All @@ -33,6 +36,9 @@ defmodule Playwright do
# @typedoc "Options for `launch`."
# @type launch_options :: Playwright.SDK.Config.launch_options()

# API
# ---------------------------------------------------------------------------

@doc """
Initiates an instance of `Playwright.Browser` use the WebSocket transport.

Expand All @@ -55,7 +61,7 @@ defmodule Playwright do
options = Map.merge(Config.connect_options(), options)
{:ok, session} = new_session(Playwright.SDK.Transport.WebSocket, options)
{:ok, browser} = new_browser(session, client, options)
{:ok, browser}
{:ok, session, browser}
end

@doc """
Expand All @@ -67,7 +73,7 @@ defmodule Playwright do

## Arguments

| key/name | typ | | description |
| key/name | type | | description |
| ----------| ----- | ----------- | ----------- |
| `client` | param | `client()` | The type of client (browser) to launch. |
| `options` | param | `options()` | `Playwright.SDK.Config.launch_options()` |
Expand All @@ -77,24 +83,33 @@ defmodule Playwright do
options = Map.merge(Config.launch_options(), options)
{:ok, session} = new_session(Playwright.SDK.Transport.Driver, options)
{:ok, browser} = new_browser(session, client, options)
{:ok, browser}
{:ok, session, browser}
end

def request(session) do
APIRequest.new(session)
end

# private
# ----------------------------------------------------------------------------

defp new_browser(session, client, options)
when is_atom(client) and client in [:chromium, :firefox, :webkit] do
with play <- Playwright.SDK.Channel.find(session, {:guid, "Playwright"}),
with play <- Channel.find(session, {:guid, "Playwright"}),
guid <- Map.get(play, client)[:guid] do
{:ok, Playwright.SDK.Channel.post(session, {:guid, guid}, :launch, options)}
playwright = %Playwright{
guid: guid,
session: session
}

{:ok, Channel.post({playwright, :launch}, options)}
end
end

defp new_session(transport, args) do
DynamicSupervisor.start_child(
Playwright.SDK.Channel.Session.Supervisor,
{Playwright.SDK.Channel.Session, {transport, args}}
Channel.Session.Supervisor,
{Channel.Session, {transport, args}}
)
end
end
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
defmodule Playwright.SDK.Channel.Error do
defmodule Playwright.API.Error do
@moduledoc false
# `Error` represents an error message received from the Playwright server
# that is in response to a `Message` previously sent.
alias Playwright.SDK.Channel

@enforce_keys [:type, :message]
defstruct [:type, :message]
defstruct [:type, :message, :wrapped]

@type t() :: %__MODULE__{
type: String.t(),
message: String.t()
message: String.t(),
wrapped: any()
}

def new(%{error: %{name: name, message: message, wrapped: original} = _error}, _catalog) do
%__MODULE__{
type: name,
message: String.split(message, "\n") |> List.first(),
wrapped: original
}
end

def new(%{error: %{name: name, message: message} = _error}, _catalog) do
%Channel.Error{
%__MODULE__{
type: name,
message: String.split(message, "\n") |> List.first()
}
end

# TODO: determine why we get here...
# DONE: see comment at error_handling.ex:9.
def new(%{error: %{message: message} = _error}, _catalog) do
%Channel.Error{
type: "NotImplementedError",
# dbg(error)

%__MODULE__{
type: "UnknownError",
message: String.split(message, "\n") |> List.first()
}
end
Expand Down
Empty file.
Loading
Loading