# std/browsers

Theme:

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

This module implements a simple proc for opening URLs with the user's default browser.

Unstable API.

# Imports

since, strutils, assertions, os, osproc

# Consts

    osOpenCmd = "xdg-open"

  Alias for the operating system specific "open" command, `"open"` on OSX, MacOS and Windows, `"xdg-open"` on Linux, BSD, etc. Source Edit

# Procs

    proc openDefaultBrowser() {....raises: [IOError],
                                tags: [ExecIOEffect, ReadEnvEffect, RootEffect],
                                forbids: [].}

  Opens the user's default browser without any `url` (blank page). This does not block. Implements IETF RFC-6694 Section 3, "about:blank" must be reserved for a blank page.

  Under Windows, `ShellExecute` is used. Under Mac OS X the `open` command is used. Under Unix, it is checked if `xdg-open` exists and used if it does. Otherwise the environment variable `BROWSER` is used to determine the default browser to use.

  This proc doesn't raise an exception on error, beware.

      block: openDefaultBrowser()

  See also:

  - https://tools.ietf.org/html/rfc6694#section-3
  Source Edit

    proc openDefaultBrowser(url: string) {....raises: [IOError, ValueError, OSError], tags: [
        ExecIOEffect, ReadEnvEffect, RootEffect], forbids: [].}

  Opens `url` with the user's default browser. This does not block. The URL must not be empty string, to open on a blank page see `openDefaultBrowser()`.

  Under Windows, `ShellExecute` is used. Under Mac OS X the `open` command is used. Under Unix, it is checked if `xdg-open` exists and used if it does. Otherwise the environment variable `BROWSER` is used to determine the default browser to use.

  This proc doesn't raise an exception on error, beware.

      block: openDefaultBrowser("https://nim-lang.org")

  Source Edit