Skip to content

Instantly share code, notes, and snippets.

@oltarasenko
Created April 19, 2021 11:32
Show Gist options
  • Save oltarasenko/fc442f909f2035c7d636ec184590330e to your computer and use it in GitHub Desktop.
Save oltarasenko/fc442f909f2035c7d636ec184590330e to your computer and use it in GitHub Desktop.
def fetch(request, client_options) do
# Start new browser session, with some extra parameters
{:ok, session} =
Wallaby.start_session(
capabilities: %{
javascriptEnabled: true,
chromeOptions: %{args: ["--headless"]}
}
)
# Visit the requested URL and fetch the page body
body =
Wallaby.Browser.visit(session, request.url)
|> Wallaby.Browser.page_source()
url = Wallaby.Browser.current_url(session)
# Don't forget to release resource, so you don't end up with millions of opened
# browser windows
:ok = Wallaby.end_session(session)
# Finally return a structure which looks like a HTTPoison response
{:ok, %HTTPoison.Response{status_code: 200, body: body, request_url: url}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment