webview

Documentation
Login

Documentation

Web View API

(import webview)

This multi-platform library for CHICKEN allows you to show HTML user interfaces in a window, inject JavaScript code and HTML content into the page and receive messages from JavaScript on the page.

Web View

(webview? VALUE) ⇒ BOOLEAN

Predicate for the tagged pointer type representing a web view window.

(webview TITLE PROC [#:url URL] [#:width WIDTH] [#:height HEIGHT] [#:resizable? RESIZABLE] [#:debug? DEBUG] [#:yield! YIELD]) ⇒ VOID

Creates a web view window with the given TITLE and runs an event loop until the user closes the window or termination is requested using webview-terminate!.

The message callback is invoked as (PROC WEBVIEW STRING) whenever a script on the web page calls window.external.invoke(STRING).

If you specify a URL that is not #f, the page at that location is loaded into the web view. Otherwise, a blank page is loaded which sends a "load" message when ready and contains a <div id="app"> element that you can fill with custom content, for example using webview-html-set!.

Window properties may be specified using the WIDTH, HEIGHT and RESIZABLE keyword arguments. If the DEBUG keyword argument is not #f and the platform supports it, the web view will allow access to debugging tools.

If YIELD is not given or #f, the event loop will block the operating system thread when no events are pending. You can set YIELD to a number of seconds sleep period between iterations of the web view event loop; this reduces responsiveness of the user interface but allows other CHICKEN threads to run and does not hog the CPU. You can also set YIELD to #t to call thread-yield! between iterations of the event loop; this allows other CHICKEN threads to run without delaying user interface event processing but will use a lot of CPU cycles.

(webview-terminate! WEBVIEW) ⇒ VOID

Requests termination of the event loop for the given WEBVIEW.

(webview-title-set! WEBVIEW TITLE) ⇒ VOID

Sets the TITLE of the given WEBVIEW window.

(webview-fullscreen-set! WEBVIEW FULLSCREEN) ⇒ VOID

Changes the FULLSCREEN state of the given WEBVIEW window.

(webview-eval WEBVIEW SCRIPT) ⇒ VOID

Asynchronously triggers evaluation of the given SCRIPT code in the context of the page displayed by the given WEBVIEW.

(webview-style-set! WEBVIEW SELECTOR PROPERTY VALUE [PRIORITY]) ⇒ VOID

Asynchronously triggers a style modification of all DOM elements matching the given SELECTOR on the page displayed by the given WEBVIEW. The given style PROPERTY is set to the given VALUE for the selected elements, optionally specifying a PRIORITY other than the default.

SELECTOR is specified as for CSS.

(webview-style-delete! WEBVIEW SELECTOR PROPERTY) ⇒ VOID

Asynchronously triggers a style modification of all DOM elements matching the given SELECTOR on the page displayed by the given WEBVIEW. The given style PROPERTY is removed from the selected elements.

SELECTOR is specified as for CSS.

(webview-html-set! WEBVIEW SELECTOR HTML [OUTER?]) ⇒ VOID

Asynchronously triggers replacement of the first DOM element matching the given SELECTOR on the page displayed by the given WEBVIEW with the given HTML content.

SELECTOR is specified as for CSS.

HTML content is specified in the form accepted by write-html.

If OUTER? is #f or not given, only the contents of the specified element are replaced, otherwise the entire element is replaced.

(webview-html-delete! WEBVIEW SELECTOR [OUTER?]) ⇒ VOID

Asynchronously triggers removal of the first DOM element matching the given SELECTOR from the page displayed by the given WEBVIEW.

SELECTOR is specified as for CSS.

If OUTER? is #f or not given, only the contents of the specified element are removed, otherwise the entire element is deleted.

Dialogs

(webview-dialog WEBVIEW TITLE TYPE [VALUE]) ⇒ VALUE

Shows a modal dialog with the given TITLE in the context of the given WEBVIEW.

If TYPE is #:open or #:save, a file selection dialog is shown and VALUE may be the path to a file that will be pre-selected. If TYPE is #:open-directory, the dialog allows the selection of directories rather than regular files. The procedure will return the path to a selected file or #f in case the dialog is cancelled.

If TYPE is #:info, #:warning or #:error, a message dialog is shown and VALUE is the message to display in the dialog. The procedure will not return a meaningful result in this case.

The running operating system thread will be blocked until the dialog is dismissed.

Logging

(webview-log MESSAGE) ⇒ VOID

Outputs a message using a platform-specific logging mechanism.

Content Generation

(import webview-content)

This support module contains procedures that write JavaScript strings and HTML document trees with proper escaping.

char-set:no-js-escape

A SRFI-14 set of characters that do not need to be escaped inside a JavaScript string.

(write-js STRING [PORT] [QUOTES]) ⇒ VOID

Writes a STRING to the given PORT or the current output port using JavaScript escaping rules. If QUOTES is given and not #f, its content is printed before and after the STRING contents. If QUOTES is not given, double quotes are put around the string.

(html-tag-rule TAG) ⇒ RULE

(html-tag-rule TAG RULE) ⇒ VOID

Retrieves or sets the content rule for HTML elements named TAG. The RULE can be one of the symbols normal, raw or void.

(write-html ELEMENT [PORT]) ⇒ VOID

Writes an HTML5 rendering of the X-expression ELEMENT to the given PORT or the current output port.

ELEMENT must conform to the following grammar:

  X-EXPR  = ELEMENT
          | CONTENT
  ELEMENT = (SYMBOL ((SYMBOL CONTENT ...) ...) X-EXPR ...) ;; element with optional attributes
          | (SYMBOL X-EXPR ...)                            ;; element without attributes
  CONTENT = STRING                                         ;; character data
          | SYMBOL                                         ;; symbolic entity reference
          | INTEGER                                        ;; numeric entity reference

If the tag symbol of the element is html, an HTML5 document type declaration is written before the element itself.

If the tag symbol of the element is begin, attributes are not allowed and only the contents are written as for a normal element.