Skip to content

UrlLauncher

Category: Core

Source: url_launcher.dart

Opens URLs in the user's default browser.

Platform-agnostic wrapper over the usual open-a-URL commands:

  • macOS: open <url> (argv, no shell)
  • Windows: rundll32 url.dll,FileProtocolHandler <url> (argv, no shell — avoids the cmd /c start metachar interpretation that would treat &, ^, | etc. as shell operators on URLs merged from untrusted catalogs)
  • other: xdg-open <url> (Linux, BSD, Unix-likes)

URLs are validated before launch: only http/https schemes are allowed and any character that cmd.exe would special-case (& | ^ < > " ` plus control chars) is rejected even on non-Windows, as defence in depth.

The runner is injectable so tests don't spawn real processes.

Functions

Future<bool> openInBrowser(String url, {ProcessRunner? runner})

Open [url] in the default browser. Returns false (never throws) when:

  • [url] isn't http/https or contains shell metacharacters
  • the launched command exits non-zero
  • the launcher itself throws (ProcessException, etc.)

`Future<bool> openLocalFileInBrowser(

String path, { ProcessRunner? runner, FileExistsCheck? fileExists, })`

Open a local HTML file in the user's default browser.

Returns false (never throws) when:

  • [path] is empty, unsafe, missing, or not an .html/.htm file
  • the launched command exits non-zero
  • the launcher itself throws (ProcessException, etc.)

Released under the MIT License.