Skip to content
Open
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion lib/chromic_pdf/pdf/connection/inet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ if Code.ensure_loaded?(WebSockex) do
:inets.start()

url = String.to_charlist("http://#{host}:#{port}/json/version")
headers = [{~c"accept", ~c"application/json"}]
# Chrome requires the "host" header to be set to either an ip address or localhost,
# otherwise it will not accept the connection
headers = [{~c"accept", ~c"application/json"}, {~c"host", ~c"localhost"}]
http_request_opts = [ssl: [verify: :verify_none]]

case :httpc.request(:get, {url, headers}, http_request_opts, []) do
{:ok, {_, _, body}} ->
body
|> Jason.decode!()
|> Map.fetch!("webSocketDebuggerUrl")
# replace the "localhost" we've provided using the "host" header with
# the actual address of the chrome instance
|> String.replace("localhost", "#{host}:#{port}")


{:error, {:failed_connect, _}} ->
raise ConnectionLostError, "failed to connect to #{url}"
Expand Down