package js_of_ocaml

  1. Overview
  2. Docs

Module Js_of_ocaml.NotificationSource

Notifications API.

A code example:

  if Notification.is_supported ()
  then
    ignore
      (Promise.map
         (fun perm ->
           if Js.to_string perm = "granted"
           then
             let options = Notification.empty_options () in
             options##.body := Js.string "Hello from OCaml!";
             ignore (new%js Notification.notification_with_options
                       (Js.string "Title") options))
         (Notification.request_permission ()))
Sourceclass type notificationAction = object ... end

A single action shown alongside a (persistent) notification. Used both when building notificationOptions and when reading notification's actions; the members are therefore read-write.

Sourceclass type notificationOptions = object ... end

Initializer for notification. All fields are optional; create an empty record with empty_options and populate the ones you need.

Sourceval empty_options : unit -> notificationOptions Js.t
Sourceclass type notification = object ... end
Sourceval permission : unit -> Js.js_string Js.t

The current permission to display notifications: "granted", "denied" or "default".

Sourceval max_actions : unit -> int

The maximum number of actions supported by notifications on this device.

Sourceval request_permission : unit -> Js.js_string Js.t Promise.t

Request permission from the user to display notifications. The promise resolves with the new permission value (see permission).

Sourceval is_supported : unit -> bool

Whether the Notification global is available in the current environment.