dachshund/ffi

FFI bindings for browser APIs.

These functions provide cross-platform access to browser features for locale detection. On Erlang, they return safe defaults.

You typically don’t need to use these directly—use the strategy functions in dachshund/strategy instead.

Types

Options for setting cookies.

pub type CookieOptions {
  CookieOptions(path: String, max_age: Int, same_site: String)
}

Constructors

  • CookieOptions(path: String, max_age: Int, same_site: String)

Values

pub fn cookie_options(
  path path: String,
  max_age max_age: Int,
  same_site same_site: String,
) -> CookieOptions

Create cookie options.

Parameters

  • path: The cookie path (use "/" for entire site)
  • max_age: Seconds until the cookie expires
  • same_site: Cross-site policy ("strict", "lax", or "none")

Example

let options = ffi.cookie_options("/", 31536000, "lax")
ffi.set_cookie("locale", "en", options)
pub fn delete_cookie(name: String) -> Nil

Delete a cookie by name.

Note: To delete a cookie, you may need to set its path to match the original path it was set with.

pub fn delete_local_storage(key: String) -> Nil

Delete a value from localStorage by key.

pub fn get_cookie(name: String) -> Result(String, Nil)

Get a cookie value by name.

Returns Error(Nil) if the cookie doesn’t exist. On Erlang, always returns Error(Nil).

pub fn get_document_lang() -> String

Get the lang attribute from the <html> element.

On Erlang, returns "en".

pub fn get_hostname() -> String

Get the current hostname (e.g., "example.com").

pub fn get_local_storage(key: String) -> Result(String, Nil)

Get a value from localStorage by key.

Returns Error(Nil) if the key doesn’t exist. On Erlang, always returns Error(Nil).

pub fn get_pathname() -> String

Get the current URL pathname (e.g., "/en/about").

On Erlang, returns "".

pub fn get_preferred_languages() -> List(String)

Get the user’s preferred languages from the browser.

Returns a list like ["en-US", "en", "es"] from navigator.languages. On Erlang, returns ["en"].

pub fn get_search() -> String

Get the current URL search string (e.g., "?lang=en").

pub fn replace_url(url: String) -> Nil

Replace the current URL without reloading the page.

pub fn set_cookie(
  name: String,
  value: String,
  options: CookieOptions,
) -> Nil

Set a cookie with the given name, value, and options.

pub fn set_local_storage(key: String, value: String) -> Nil

Set a value in localStorage.

Search Document