Module Js_of_ocaml.Notification

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 ()))
class 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.

class type notificationOptions = object ... end

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

val empty_options : unit -> notificationOptions Js.t
class type notification = object ... end
val notification : (Js.js_string Js.t -> notification Js.t) Js.constr
val notification_with_options : (Js.js_string Js.t -> notificationOptions Js.t -> notification Js.t) Js.constr
val permission : unit -> Js.js_string Js.t

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

val max_actions : unit -> int

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

val 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).

val is_supported : unit -> bool

Whether the Notification global is available in the current environment.