drab v0.6.0-pre.1 Drab.Browser
Browser related functions.
Provides information about connected browser, such as local datetime, user agent.
Link to this section Summary
Functions
Sends the log to the browser console for debugging
Broadcasts the log to the browser consoles for debugging/
Returns browser language
Returns a list of browser supported languages
Returns local browser time as NaiveDateTime. Timezone information is not included
Redirects to the given url
Broadcast version of redirect_to
Replaces the URL in the browser navigation bar for the given URL
Returns browser information (userAgent)
Returns utc offset (the difference between local browser time and UTC time), in seconds
Link to this section Functions
Sends the log to the browser console for debugging.
Broadcasts the log to the browser consoles for debugging/
Returns browser language.
Example:
iex> Drab.Browser.language(socket)
"en-GB"
Returns a list of browser supported languages.
Example:
iex> Drab.Browser.languages(socket)
["en-US", "en", "pl"]
Returns local browser time as NaiveDateTime. Timezone information is not included.
Examples:
iex> Drab.Browser.now(socket)
~N[2017-04-01 15:07:57.027000]
Redirects to the given url.
WARNING: redirection will disconnect the current websocket, so it should be the last function launched in the handler.
Broadcast version of redirect_to
.
WARNING: redirection will disconnect the current websocket, so it should be the last function launched in the handler.
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 with URL 'http://google.com/'
cannot be created in a document with origin 'http://localhost:4000' and URL 'http://localhost:4000/'."}
Returns browser information (userAgent).
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)
7200 # UTC + 02:00