On this page:
send-url
send-url/  file
send-url/  contents
send-url/  mac
external-browser
browser-preference?
browser-list
unix-browser-list

5 Send URL: Opening a Web Browser🔗ℹ

Provides send-url for opening a URL in the user’s chosen web browser.

See also browser/external, which requires racket/gui, but can prompt the user for a browser if no browser preference is set.

procedure

(send-url str    
  [separate-window?    
  #:escape? escape?])  void?
  str : string?
  separate-window? : any/c = #t
  escape? : any/c = #t
Opens str, which represents a URL, in a platform-specific manner. In particular, the first value in browser-list will determine which browser will be used to open the URL. For some platforms and configurations, the separate-window? parameter determines if the browser creates a new window to display the URL or not.

If escape? is true, then str is escaped (by UTF-8 encoding followed by “%” encoding) to avoid dangerous shell characters: single quotes, double quotes, backquotes, dollar signs, backslashes, non-ASCII characters, and non-graphic characters. Note that escaping does not affect already-encoded characters in str.

There are two ways to override the above behavior: the external-browser parameter and the 'external-browser preference. A valid setting for both the external-browser parameter and the 'external-browser preference must satisfy browser-preference?, with a restriction that the setting for the 'external-browser preference cannot be a procedure. The external-browser parameter takes priority over 'external-browser preference: the preference is only used when (external-browser) is #f. See put-preferences for details on setting preferences.

On Unix, it’s recommended to not override the default behavior, but to rely on xdg-open in browser-list.

procedure

(send-url/file path    
  [separate-window?    
  #:fragment fragment    
  #:query query])  void?
  path : path-string?
  separate-window? : any/c = #t
  fragment : (or/c string? #f) = #f
  query : (or/c string? #f) = #f
Similar to send-url (with #:escape? #t), but accepts a path to a file to be displayed by the browser, along with optional fragment (with no leading #) and query (with no leading ?) strings. Use send-url/file to display a local file, since it takes care of the peculiarities of constructing the correct file:// URL.

The path, fragment, and query arguments are all encoded in the same way as a path provided to send-url, which means that already-encoded characters are used as-is.

procedure

(send-url/contents contents    
  [separate-window?    
  #:fragment fragment    
  #:query query    
  #:delete-at seconds])  void?
  contents : string?
  separate-window? : any/c = #t
  fragment : (or/c string? #f) = #f
  query : (or/c string? #f) = #f
  seconds : (or/c number? #f) = #f
Similar to send-url/file, but it consumes the contents of a page to show and displays it from a temporary file.

When send-url/contents is called, it scans old generated files (this happens randomly, not on every call) and removes them to avoid cluttering the temporary directory. If the seconds argument is a number, then the temporary file is more eagerly removed after the specified number of seconds; the deletion happens in a thread, so if Racket exits earlier, the deletion will not happen. If the seconds argument is #f, no eager deletion happens, but old temporary files are still deleted as described above.

procedure

(send-url/mac url [#:browser browser])  void?

  url : string?
  browser : (or/c string? #f) = #f
Like send-url, but only for use on a Mac OS machine.

The optional browser argument, if present, should be the name of a browser installed on the system. For example,

(send-url/mac "https://www.google.com/" #:browser "Firefox")

would open the url in Firefox, even if that’s not the default browser. Passing #f means to use the default browser.

A parameter that can hold a browser preference to override how a browser is started for send-url. See browser-preference? for details.

procedure

(browser-preference? a)  boolean?

  a : any/c
Returns #t if v is a valid browser preference, #f otherwise. A valid browser preference is either:

A list of symbols representing executable names that may be tried in order by send-url. The send-url function internally includes information on how to launch each executable with a URL.

Added in version 7.5.0.10 of package net-lib.

NOTE: This value is deprecated; use browser-list, instead.

The same as browser-list.

Changed in version 7.5.0.10 of package net-lib: Changed the value to be an alias of browser-list.