drab v0.8.3 Drab.Browser
Browser related functions.
Provides information about connected browser, such as local datetime, user agent.
Link to this section Summary
Functions
Broadcasts the log to the browser consoles for debugging/
Broadcast version of redirect_to/2
Like set_url/2
, but broadcasting the change to all connected browsers
Sends the log to the browser console for debugging
Returns string with the browser unique id
Returns string with the browser unique id
Returns browser language
Bang version of language/1
Returns a list of browser supported languages
Bang version of language/1
Returns local browser time as NaiveDateTime. Timezone information is not included
Bang version of now/1
. Raises exception on error
Redirects to the given url
Replaces the URL in the browser navigation bar for the given URL
Exception throwing version of set_url/2
Returns browser information (userAgent)
Bang version of user_agent/1
Returns utc offset (the difference between local browser time and UTC time), in seconds
Returns utc offset (the difference between local browser time and UTC time), in seconds. Raises exception on error
Link to this section Functions
broadcast_console(Phoenix.Socket.t(), String.t()) :: Drab.Core.bcast_result()
Broadcasts the log to the browser consoles for debugging/
broadcast_redirect_to(Phoenix.Socket.t(), String.t()) :: any()
Broadcast version of redirect_to/2
.
WARNING: redirection will disconnect the current websocket, so it should be the last function launched in the handler.
broadcast_set_url(Phoenix.Socket.t(), String.t()) :: Drab.Core.bcast_result()
Like set_url/2
, but broadcasting the change to all connected browsers.
console(Phoenix.Socket.t(), String.t()) :: Drab.Core.result()
Sends the log to the browser console for debugging.
Returns string with the browser unique id.
The id is generated on the client side and stored in local store.
iex> Drab.Browser.id(socket)
{:ok, "2bd34ffc-b365-46a9-9479-474b628364ed"}
Returns string with the browser unique id.
Bang version of id/1
.
Returns browser language.
Example:
iex> Drab.Browser.language(socket)
{:ok, "en-GB"}
Bang version of language/1
.
Example:
iex> Drab.Browser.language!(socket)
"en-GB"
Returns a list of browser supported languages.
Example:
iex> Drab.Browser.languages(socket)
{:ok, ["en-US", "en", "pl"]}
Bang version of language/1
.
Example:
iex> Drab.Browser.languages!(socket)
["en-US", "en", "pl"]
now(Phoenix.Socket.t()) :: {Drab.Core.status(), NaiveDateTime.t()}
Returns local browser time as NaiveDateTime. Timezone information is not included.
Examples:
iex> Drab.Browser.now(socket)
{:ok, ~N[2017-04-01 15:07:57.027000]}
Bang version of now/1
. Raises exception on error.
Examples:
iex> Drab.Browser.now!(socket)
~N[2017-04-01 15:07:57.027000]
redirect_to(Phoenix.Socket.t(), String.t()) :: Drab.Core.result()
Redirects to the given url.
WARNING: redirection will disconnect the current websocket, so it should be the last function launched in the handler.
set_url(Phoenix.Socket.t(), String.t()) :: Drab.Core.result()
Replaces the URL in the browser navigation bar for the given URL.
The new URL can be absolute or relative to the current path. It must have the same origin as the current one.
iex> Drab.Browser.set_url socket, "/servers/1"
{:ok, nil}
iex> Drab.Browser.set_url socket, "http://google.com/"
{:error,
"Failed to execute 'pushState' on 'History': A history state object ...'
cannot be created in a document with origin 'http://localhost:4000' ..."}
Exception throwing version of set_url/2
.
iex> Drab.Browser.set_url! socket, "/servers/1"
nil
iex> Drab.Browser.set_url! socket, "http://google.com/"
** (Drab.JSExecutionError) Failed to execute 'pushState' on 'History' ...
Returns browser information (userAgent).
Examples:
iex> Drab.Browser.user_agent(socket)
{:ok, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 ..."}
Bang version of user_agent/1
.
Examples:
iex> Drab.Browser.user_agent!(socket)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) ..."
Returns utc offset (the difference between local browser time and UTC time), in seconds.
Examples:
iex> Drab.Browser.utc_offset(socket)
{:ok, 7200} # UTC + 02:00
Returns utc offset (the difference between local browser time and UTC time), in seconds. Raises exception on error.
Examples:
iex> Drab.Browser.utc_offset!(socket)
7200 # UTC + 02:00