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

Link to this function console(socket, log)

Sends the log to the browser console for debugging.

Link to this function console!(socket, log)

Broadcasts the log to the browser consoles for debugging/

Link to this function language(socket)

Returns browser language.

Example:

iex> Drab.Browser.language(socket)  
"en-GB"
Link to this function languages(socket)

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]
Link to this function redirect_to(socket, url)

Redirects to the given url.

WARNING: redirection will disconnect the current websocket, so it should be the last function launched in the handler.

Link to this function redirect_to!(socket, url)

Broadcast version of redirect_to.

WARNING: redirection will disconnect the current websocket, so it should be the last function launched in the handler.

Link to this function set_url(socket, url)

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/'."}
Link to this function user_agent(socket)

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) ..."
Link to this function utc_offset(socket)

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