Created
April 19, 2021 11:32
-
-
Save oltarasenko/fc442f909f2035c7d636ec184590330e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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