Current section
Files
Jump to
Current section
Files
src/butterbee@browser.erl
-module(butterbee@browser).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/butterbee/browser.gleam").
-export([new/1, with_cmd/2, with_request/2, with_profile_name/2, with_profile_dir/2, get_request/2, new_port/0, new_profile/1]).
-export_type([browser/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" The browser module contains the Browser type and functions to create and configure browsers.\n"
"\n"
" Usually you will not need to use this module directly, as it is usually derived\n"
" from the configuration in the gleam.toml file. But you can pass it as a type using\n"
" the [`driver.new_with_config`](https://hexdocs.pm/butterbee/driver.html#new_with_config)\n"
" function.\n"
).
-type browser() :: {browser,
butterbee@config@browser:browser_type(),
gleam@option:option({binary(), list(binary())}),
gleam@option:option(gleam@http@request:request(binary())),
gleam@option:option(binary()),
gleam@option:option(binary())}.
-file("src/butterbee/browser.gleam", 46).
-spec new(butterbee@config@browser:browser_type()) -> browser().
new(Browser_to_run) ->
{browser, Browser_to_run, none, none, none, none}.
-file("src/butterbee/browser.gleam", 56).
-spec with_cmd(browser(), {binary(), list(binary())}) -> browser().
with_cmd(Browser, Cmd) ->
{browser,
erlang:element(2, Browser),
{some, Cmd},
erlang:element(4, Browser),
erlang:element(5, Browser),
erlang:element(6, Browser)}.
-file("src/butterbee/browser.gleam", 60).
-spec with_request(browser(), gleam@http@request:request(binary())) -> browser().
with_request(Browser, Request) ->
{browser,
erlang:element(2, Browser),
erlang:element(3, Browser),
{some, Request},
erlang:element(5, Browser),
erlang:element(6, Browser)}.
-file("src/butterbee/browser.gleam", 64).
-spec with_profile_name(browser(), binary()) -> browser().
with_profile_name(Browser, Profile_name) ->
{browser,
erlang:element(2, Browser),
erlang:element(3, Browser),
erlang:element(4, Browser),
{some, Profile_name},
erlang:element(6, Browser)}.
-file("src/butterbee/browser.gleam", 68).
-spec with_profile_dir(browser(), binary()) -> browser().
with_profile_dir(Browser, Profile_dir) ->
{browser,
erlang:element(2, Browser),
erlang:element(3, Browser),
erlang:element(4, Browser),
erlang:element(5, Browser),
{some, Profile_dir}}.
-file("src/butterbee/browser.gleam", 72).
-spec get_request(integer(), binary()) -> gleam@http@request:request(binary()).
get_request(Port, Host) ->
_pipe = gleam@http@request:new(),
_pipe@1 = gleam@http@request:set_host(_pipe, Host),
_pipe@2 = gleam@http@request:set_port(_pipe@1, Port),
_pipe@3 = gleam@http@request:set_path(_pipe@2, <<"/session"/utf8>>),
gleam@http@request:set_scheme(_pipe@3, http).
-file("src/butterbee/browser.gleam", 83).
?DOC(" Returns a free port to use for a webdriver session\n").
-spec new_port() -> {ok, integer()} |
{error, butterbee@internal@error:port_error()}.
new_port() ->
browser_ffi:new_port().
-file("src/butterbee/browser.gleam", 87).
?DOC(
" Create a new profile directory\n"
" Returns the name of the profile\n"
).
-spec new_profile(binary()) -> {ok, {binary(), binary()}} |
{error, simplifile:file_error()}.
new_profile(Data_dir) ->
Profile_name = erlang:integer_to_binary(butterbee@internal@id:from_unix()),
Profile_dir = <<<<Data_dir/binary, "/"/utf8>>/binary, Profile_name/binary>>,
Profile = begin
_pipe = simplifile:create_directory_all(Profile_dir),
gleam@result:map(_pipe, fun(_) -> {Profile_name, Profile_dir} end)
end,
_pipe@1 = palabres:debug(<<"Creating profile"/utf8>>),
_pipe@2 = palabres:string(_pipe@1, <<"profile dir"/utf8>>, Profile_dir),
_pipe@3 = palabres:string(_pipe@2, <<"profile name"/utf8>>, Profile_name),
palabres:log(_pipe@3),
Profile.