Skip to main content

Platform

A set of essential interfaces and functions to interact with the browser environment. Eg handling user interactions, getting browser and device information, scheduling and canceling periodic or one-time tasks.

prompt, console

Functions

f
alert

Shows the given message and waits for the enter key pressed.

    f
    close

    Exits the current Deno process.

      f
      confirm

      Shows the given message and waits for the answer. Returns the user's answer as boolean.

        f
        prompt

        Shows the given message and waits for the user's input. Returns the user's input as string.

          f
          queueMicrotask

          A microtask is a short function which is executed after the function or module which created it exits and only if the JavaScript execution stack is empty, but before returning control to the event loop being used to drive the script's execution environment. This event loop may be either the main event loop or the event loop driving a web worker.

            f
            reportError

            Dispatch an uncaught exception. Similar to a synchronous version of:

              f
              structuredClone

              Creates a deep copy of a given value using the structured clone algorithm.

                Interfaces

                I
                v
                AbortController

                A controller object that allows you to abort one or more DOM requests as and when desired.

                I
                v
                AbortSignal

                A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object.

                I
                AbortSignalEventMap
                No documentation available
                I
                DomIterable
                No documentation available
                I
                DOMStringList
                No documentation available
                I
                ImageDataSettings
                No documentation available
                I
                ImportMeta

                Deno provides extra properties on import.meta. These are included here to ensure that these are still available when using the Deno namespace in conjunction with other type libs, like dom.

                I
                v
                Location

                The location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Accessible via globalThis.location.

                I
                Math
                No documentation available
                I
                v
                Navigator

                Provides information about the Deno runtime environment and the system on which it's running. Similar to the browser Navigator object but adapted for the Deno context.

                I
                v
                QuotaExceededError

                Represents an error when a quota has been exceeded.

                I
                QuotaExceededErrorOptions
                No documentation available
                I
                RegExpConstructor
                No documentation available
                I
                StructuredSerializeOptions

                Options that control structured serialization operations such as structuredClone(value, options) and MessagePort.postMessage(message, options).

                I
                Uint8ArrayConstructor
                No documentation available
                I
                VoidFunction
                No documentation available
                  I
                  WebTransportCloseInfo
                  No documentation available
                  I
                  WebTransportHash
                  No documentation available
                  I
                  WindowEventMap

                  Defines the mapping between event names and their corresponding event types for the Window interface in Deno.

                  Type Aliases

                  T
                  AllowSharedBufferSource
                  No documentation available
                    T
                    BufferSource
                    No documentation available
                      T
                      ImageDataArray
                      No documentation available
                        T
                        ImageDataPixelFormat
                        No documentation available
                          T
                          PredefinedColorSpace
                          No documentation available
                            T
                            WebTransportCongestionControl
                            No documentation available
                              T
                              WebTransportErrorSource
                              No documentation available

                                Variables

                                v
                                closed

                                Indicates whether the current window (context) is closed. In Deno, this property is primarily for API compatibility with browsers.

                                  v
                                  location

                                  The Location object describing the absolute URL of the main module, available when the program is started with the --location flag. Accessing it without --location throws.

                                    v
                                    name

                                    Gets or sets the name of the global scope's browsing context.

                                      v
                                      navigator

                                      Provides access to the Deno runtime's Navigator interface, which contains information about the environment in which the script is running.

                                        v
                                        self

                                        Reference to the global object itself. Equivalent to the global window object in browser environments.


                                          function alert

                                          #alert(message?: string): void

                                          Shows the given message and waits for the enter key pressed.

                                          If the stdin is not interactive, it does nothing.

                                          Examples #

                                          #
                                          // Displays the message "Acknowledge me! [Enter]" and waits for the enter key to be pressed before continuing.
                                          alert("Acknowledge me!");
                                          

                                          Parameters #

                                          #message: string
                                          optional

                                          Return Type #

                                          void

                                          See #


                                          function close

                                          #close(): void

                                          Exits the current Deno process.

                                          This function terminates the process by signaling the runtime to exit. Similar to exit(0) in posix. Its behavior is similar to the window.close() method in the browser, but specific to the Deno runtime.

                                          Note: Use this function cautiously, as it will stop the execution of the entire Deno program immediately.

                                          Examples #

                                          #
                                          console.log("About to close the Deno process.");
                                          close(); // The process will terminate here.
                                          console.log("This will not be logged."); // This line will never execute.
                                          

                                          Return Type #

                                          void

                                          See #


                                          function confirm

                                          #confirm(message?: string): boolean

                                          Shows the given message and waits for the answer. Returns the user's answer as boolean.

                                          Only y and Y are considered as true.

                                          If the stdin is not interactive, it returns false.

                                          Examples #

                                          #
                                          const shouldProceed = confirm("Do you want to proceed?");
                                          
                                          // If the user presses 'y' or 'Y', the result will be true
                                          // If the user presses 'n' or 'N', the result will be false
                                          console.log("Should proceed?", shouldProceed);
                                          

                                          Parameters #

                                          #message: string
                                          optional

                                          Return Type #

                                          boolean

                                          See #


                                          function prompt

                                          #prompt(
                                          message?: string,
                                          defaultValue?: string,
                                          ): string | null

                                          Shows the given message and waits for the user's input. Returns the user's input as string.

                                          If the default value is given and the user inputs the empty string, then it returns the given default value.

                                          If the default value is not given and the user inputs the empty string, it returns the empty string.

                                          If the stdin is not interactive, it returns null.

                                          Examples #

                                          #
                                          const pet = prompt("Cats or dogs?", "It's fine to love both!");
                                          
                                          // Displays the user's input or the default value of "It's fine to love both!"
                                          console.log("Best pet:", pet);
                                          

                                          Parameters #

                                          #message: string
                                          optional
                                          #defaultValue: string
                                          optional

                                          Return Type #

                                          string | null

                                          See #


                                          function queueMicrotask

                                          #queueMicrotask(func: VoidFunction): void

                                          A microtask is a short function which is executed after the function or module which created it exits and only if the JavaScript execution stack is empty, but before returning control to the event loop being used to drive the script's execution environment. This event loop may be either the main event loop or the event loop driving a web worker.

                                          queueMicrotask(() => { console.log('This event loop stack is complete'); });
                                          

                                          Parameters #

                                          Return Type #

                                          void

                                          function reportError

                                          #reportError(error: any): void

                                          Dispatch an uncaught exception. Similar to a synchronous version of:

                                          setTimeout(() => { throw error; }, 0);
                                          

                                          The error can not be caught with a try/catch block. An error event will be dispatched to the global scope. You can prevent the error from being reported to the console with Event.prototype.preventDefault():

                                          addEventListener("error", (event) => {
                                            event.preventDefault();
                                          });
                                          reportError(new Error("foo")); // Will not be reported.
                                          

                                          In Deno, this error will terminate the process if not intercepted like above.

                                          Parameters #

                                          #error: any

                                          Return Type #

                                          void

                                          function structuredClone

                                          #structuredClone<T = any>(
                                          value: T,
                                          ): T

                                          Creates a deep copy of a given value using the structured clone algorithm.

                                          Unlike a shallow copy, a deep copy does not hold the same references as the source object, meaning its properties can be changed without affecting the source. For more details, see MDN.

                                          Throws a DataCloneError if any part of the input value is not serializable.

                                          Examples #

                                          #
                                          const object = { x: 0, y: 1 };
                                          
                                          const deepCopy = structuredClone(object);
                                          deepCopy.x = 1;
                                          console.log(deepCopy.x, object.x); // 1 0
                                          
                                          const shallowCopy = object;
                                          shallowCopy.x = 1;
                                          // shallowCopy.x is pointing to the same location in memory as object.x
                                          console.log(shallowCopy.x, object.x); // 1 1
                                          

                                          Type Parameters #

                                          #T = any

                                          Parameters #

                                          #value: T
                                          #options: StructuredSerializeOptions
                                          optional

                                          Return Type #

                                          T

                                          interface AbortController

                                          A controller object that allows you to abort one or more DOM requests as and when desired.

                                          Properties #

                                          Returns the AbortSignal object associated with this object.

                                          Methods #

                                          #abort(reason?: any): void

                                          Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.

                                          variable AbortController

                                          A controller object that allows you to abort one or more DOM requests as and when desired.

                                          Properties #


                                          interface AbortSignal

                                          extends EventTarget

                                          A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object.

                                          Properties #

                                          #aborted: boolean
                                          readonly

                                          Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.

                                          #reason: any
                                          readonly
                                          #onabort: ((
                                          ev: Event,
                                          ) => any) | null

                                          Methods #

                                          #addEventListener<K extends keyof AbortSignalEventMap>(
                                          type: K,
                                          listener: () => any,
                                          options?: boolean | AddEventListenerOptions,
                                          ): void
                                          #addEventListener(
                                          type: string,
                                          options?: boolean | AddEventListenerOptions,
                                          ): void
                                          #removeEventListener<K extends keyof AbortSignalEventMap>(
                                          type: K,
                                          listener: () => any,
                                          options?: boolean | EventListenerOptions,
                                          ): void
                                          #removeEventListener(
                                          type: string,
                                          options?: boolean | EventListenerOptions,
                                          ): void

                                          Throws this AbortSignal's abort reason, if its AbortController has signaled to abort; otherwise, does nothing.

                                          variable AbortSignal

                                          The constructor object for AbortSignal.

                                          AbortSignal instances are obtained from an AbortController or via the static abort, timeout, and any factory methods rather than constructed directly, so calling the constructor throws.

                                          Properties #

                                          Methods #

                                          #abort(reason?: any): AbortSignal
                                          #timeout(milliseconds: number): AbortSignal


                                          interface DOMException

                                          extends Error

                                          Properties #

                                          #name: string
                                          readonly
                                          #message: string
                                          readonly
                                          #code: number
                                          deprecated
                                          readonly
                                          #INDEX_SIZE_ERR: 1
                                          readonly
                                          #NOT_FOUND_ERR: 8
                                          readonly
                                          #NOT_SUPPORTED_ERR: 9
                                          readonly
                                          #INVALID_STATE_ERR: 11
                                          readonly
                                          #SYNTAX_ERR: 12
                                          readonly
                                          #NAMESPACE_ERR: 14
                                          readonly
                                          #INVALID_ACCESS_ERR: 15
                                          readonly
                                          #VALIDATION_ERR: 16
                                          readonly
                                          #TYPE_MISMATCH_ERR: 17
                                          readonly
                                          #SECURITY_ERR: 18
                                          readonly
                                          #NETWORK_ERR: 19
                                          readonly
                                          #ABORT_ERR: 20
                                          readonly
                                          #URL_MISMATCH_ERR: 21
                                          readonly
                                          #QUOTA_EXCEEDED_ERR: 22
                                          readonly
                                          #TIMEOUT_ERR: 23
                                          readonly
                                          #DATA_CLONE_ERR: 25
                                          readonly

                                          variable DOMException

                                          The constructor object for DOMException, used to construct an exception describing an abnormal event raised by a web API. It also exposes the legacy numeric error code constants (e.g. ABORT_ERR).

                                          Properties #

                                          #INDEX_SIZE_ERR: 1
                                          readonly
                                          #NOT_FOUND_ERR: 8
                                          readonly
                                          #NOT_SUPPORTED_ERR: 9
                                          readonly
                                          #INVALID_STATE_ERR: 11
                                          readonly
                                          #SYNTAX_ERR: 12
                                          readonly
                                          #NAMESPACE_ERR: 14
                                          readonly
                                          #INVALID_ACCESS_ERR: 15
                                          readonly
                                          #VALIDATION_ERR: 16
                                          readonly
                                          #TYPE_MISMATCH_ERR: 17
                                          readonly
                                          #SECURITY_ERR: 18
                                          readonly
                                          #NETWORK_ERR: 19
                                          readonly
                                          #ABORT_ERR: 20
                                          readonly
                                          #URL_MISMATCH_ERR: 21
                                          readonly
                                          #QUOTA_EXCEEDED_ERR: 22
                                          readonly
                                          #TIMEOUT_ERR: 23
                                          readonly
                                          #DATA_CLONE_ERR: 25
                                          readonly


                                          interface DOMStringList

                                          Index Signatures #

                                          #[index: number]: string

                                          Properties #

                                          #length: number
                                          readonly

                                          Returns the number of strings in strings.

                                          Methods #

                                          #contains(string: string): boolean

                                          Returns true if strings contains string, and false otherwise.

                                          #item(index: number): string | null

                                          Returns the string with index index from strings.





                                          interface ImportMeta

                                          Deno provides extra properties on import.meta. These are included here to ensure that these are still available when using the Deno namespace in conjunction with other type libs, like dom.

                                          Properties #

                                          #url: string

                                          A string representation of the fully qualified module URL. When the module is loaded locally, the value will be a file URL (e.g. file:///path/module.ts).

                                          You can also parse the string as a URL to determine more information about how the current module was loaded. For example to determine if a module was local or not:

                                          const url = new URL(import.meta.url);
                                          if (url.protocol === "file:") {
                                            console.log("this module was loaded locally");
                                          }
                                          
                                          #filename: string
                                          optional

                                          The absolute path of the current module.

                                          This property is only provided for local modules (ie. using file:// URLs).

                                          Example:

                                          // Unix
                                          console.log(import.meta.filename); // /home/alice/my_module.ts
                                          
                                          // Windows
                                          console.log(import.meta.filename); // C:\alice\my_module.ts
                                          
                                          #dirname: string
                                          optional

                                          The absolute path of the directory containing the current module.

                                          This property is only provided for local modules (ie. using file:// URLs).

                                          • Example:
                                          // Unix
                                          console.log(import.meta.dirname); // /home/alice
                                          
                                          // Windows
                                          console.log(import.meta.dirname); // C:\alice
                                          
                                          #main: boolean

                                          A flag that indicates if the current module is the main module that was called when starting the program under Deno.

                                          if (import.meta.main) {
                                            // this was loaded as the main module, maybe do some bootstrapping
                                          }
                                          

                                          Methods #

                                          #resolve(specifier: string): string

                                          A function that returns resolved specifier as if it would be imported using import(specifier).

                                          console.log(import.meta.resolve("./foo.js"));
                                          // file:///dev/foo.js
                                          

                                          interface Location

                                          The location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Accessible via globalThis.location.

                                          Properties #

                                          Returns a DOMStringList object listing the origins of the ancestor browsing contexts, from the parent browsing context to the top-level browsing context.

                                          Always empty in Deno.

                                          #hash: string

                                          Returns the Location object's URL's fragment (includes leading "#" if non-empty).

                                          Cannot be set in Deno.

                                          #host: string

                                          Returns the Location object's URL's host and port (if different from the default port for the scheme).

                                          Cannot be set in Deno.

                                          #hostname: string

                                          Returns the Location object's URL's host.

                                          Cannot be set in Deno.

                                          #href: string

                                          Returns the Location object's URL.

                                          Cannot be set in Deno.

                                          #origin: string
                                          readonly

                                          Returns the Location object's URL's origin.

                                          #pathname: string

                                          Returns the Location object's URL's path.

                                          Cannot be set in Deno.

                                          #port: string

                                          Returns the Location object's URL's port.

                                          Cannot be set in Deno.

                                          #protocol: string

                                          Returns the Location object's URL's scheme.

                                          Cannot be set in Deno.

                                          Methods #

                                          #toString(): string
                                          #assign(url: string): void

                                          Navigates to the given URL.

                                          Cannot be set in Deno.

                                          #reload(): void

                                          Reloads the current page.

                                          Disabled in Deno.

                                          #reload(forcedReload: boolean): void
                                          deprecated
                                          #replace(url: string): void

                                          Removes the current page from the session history and navigates to the given URL.

                                          Disabled in Deno.

                                          variable Location

                                          The location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Accessible via globalThis.location.

                                          Properties #


                                          interface Math

                                          Methods #

                                          #sumPrecise(values: Iterable<number>): number

                                          Returns the sum of the given values using a more precise algorithm than a naive +-based reduction, avoiding the floating-point rounding errors that accumulate when summing many numbers.

                                          MDN Reference





                                          interface RegExpConstructor

                                          unstable

                                          Methods #

                                          #escape(string: string): string

                                          Returns a new string in which characters that are potentially special in a regular expression pattern are replaced with escape sequences.


                                          interface StructuredSerializeOptions

                                          Options that control structured serialization operations such as structuredClone(value, options) and MessagePort.postMessage(message, options).

                                          The optional transfer array lists Transferable objects whose underlying resources should be moved (transferred) to the receiving side instead of being cloned. After a successful transfer:

                                          • For an ArrayBuffer, the original buffer becomes neutered (its byteLength is set to 0).
                                          • For a MessagePort, the port becomes unusable on the sending side and future events will arrive only on the transferred port at the receiver.

                                          Validation rules:

                                          • Each transferable may appear only once in the transfer list.
                                          • A MessagePort cannot be listed together with its counterpart port from the same MessageChannel in the same transfer operation.
                                          • Duplicate or otherwise invalid entries will cause a DataCloneError DOMException to be thrown.

                                          Transferring improves performance for large binary data and allows moving communication endpoints without copying.

                                          Examples #

                                          #
                                          // Transferring an ArrayBuffer (zero-copy for large data)
                                          const buffer = new ArrayBuffer(16);
                                          const cloned = structuredClone(buffer, { transfer: [buffer] });
                                          
                                          // After transfer, the original buffer is neutered
                                          console.log(buffer.byteLength); // 0
                                          console.log(cloned.byteLength); // 16
                                          

                                          Properties #

                                          List of transferable objects whose ownership is moved instead of cloned.


                                          interface Uint8Array

                                          unstable

                                          Methods #

                                          #toBase64(options?: { alphabet?: "base64" | "base64url"; omitPadding?: boolean; }): string

                                          Converts this Uint8Array object to a base64 string.

                                          MDN

                                          #setFromBase64(
                                          string: string,
                                          options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?:
                                          "loose"
                                          | "strict"
                                          | "stop-before-partial"
                                          ; }
                                          ,
                                          ): { read: number; written: number; }

                                          Populates this Uint8Array object with data from a base64 string.

                                          MDN

                                          #toHex(): string

                                          Converts this Uint8Array object to a hex string.

                                          MDN

                                          #setFromHex(string: string): { read: number; written: number; }

                                          Populates this Uint8Array object with data from a hex string.

                                          MDN


                                          interface Uint8ArrayConstructor

                                          unstable

                                          Methods #

                                          #fromBase64(
                                          string: string,
                                          options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?:
                                          "loose"
                                          | "strict"
                                          | "stop-before-partial"
                                          ; }
                                          ,
                                          ): Uint8Array<ArrayBuffer>

                                          Creates a new Uint8Array object from a base64 string.

                                          MDN

                                          #fromHex(string: string): Uint8Array<ArrayBuffer>

                                          Creates a new Uint8Array object from a hex string.

                                          MDN



                                          variable WebTransport

                                          The constructor object for WebTransport, used to open a new WebTransport session to the server at the given url.

                                          Properties #




                                          variable WebTransportDatagramDuplexStream

                                          The constructor object for WebTransportDatagramDuplexStream.

                                          The datagram duplex stream is obtained from WebTransport.datagrams rather than constructed directly.

                                          Properties #









                                          variable WebTransportSendStream

                                          The constructor object for WebTransportSendStream.

                                          Instances are obtained from a WebTransport session rather than constructed directly.

                                          Properties #





                                          interface Window

                                          extends EventTarget

                                          Represents the global window object in the Deno runtime environment.

                                          While Deno doesn't have a browser window, this interface mimics browser window functionality for compatibility with web APIs. It provides access to global properties and methods such as timers, storage, and event handling.

                                          Examples #

                                          #
                                          // Accessing global objects
                                          const localStorage = window.localStorage;
                                          
                                          // Event handling
                                          window.addEventListener("unhandledrejection", (event) => {
                                            console.log("Unhandled promise rejection:", event.reason);d
                                          });
                                          

                                          Properties #

                                          #window: Window & globalThis
                                          readonly
                                          #self: Window & globalThis
                                          readonly
                                          #onerror: ((
                                          this: Window,
                                          ) => any) | null
                                          #onload: ((
                                          this: Window,
                                          ev: Event,
                                          ) => any) | null
                                          #onbeforeunload: ((
                                          this: Window,
                                          ev: Event,
                                          ) => any) | null
                                          #onunload: ((
                                          this: Window,
                                          ev: Event,
                                          ) => any) | null
                                          #onunhandledrejection: (() => any) | null
                                          #onrejectionhandled: (() => any) | null
                                          #close: () => void
                                          #closed: boolean
                                          readonly
                                          #alert: (message?: string) => void
                                          #confirm: (message?: string) => boolean
                                          #prompt: (
                                          message?: string,
                                          defaultValue?: string,
                                          ) => string | null
                                          #Deno: Deno
                                          #name: string

                                          Methods #

                                          #addEventListener<K extends keyof WindowEventMap>(
                                          type: K,
                                          listener: (
                                          this: Window,
                                          ) => any
                                          ,
                                          options?: boolean | AddEventListenerOptions,
                                          ): void
                                          #addEventListener(
                                          type: string,
                                          options?: boolean | AddEventListenerOptions,
                                          ): void
                                          #removeEventListener<K extends keyof WindowEventMap>(
                                          type: K,
                                          listener: (
                                          this: Window,
                                          ) => any
                                          ,
                                          options?: boolean | EventListenerOptions,
                                          ): void
                                          #removeEventListener(
                                          type: string,
                                          options?: boolean | EventListenerOptions,
                                          ): void

                                          variable Window

                                          Constructor for Window objects.

                                          Note: This constructor cannot be used to create new Window instances in Deno. The global window object is pre-defined in the runtime environment.

                                          Properties #

                                          #prototype: Window
                                          readonly



                                          type alias BufferSource

                                          Definition #

                                          ArrayBufferView<ArrayBuffer> | ArrayBuffer

                                          type alias ImageDataArray

                                          Definition #

                                          Uint8ClampedArray<ArrayBuffer> | Float16Array<ArrayBuffer>





                                          variable closed

                                          Indicates whether the current window (context) is closed. In Deno, this property is primarily for API compatibility with browsers.

                                          Type #

                                          boolean

                                          variable location

                                          The Location object describing the absolute URL of the main module, available when the program is started with the --location flag. Accessing it without --location throws.

                                          Type #


                                          variable name

                                          Gets or sets the name of the global scope's browsing context.

                                          Provided for web compatibility; Deno has no browsing context, so this is an empty string by default.

                                          Type #

                                          string


                                          variable self

                                          Reference to the global object itself. Equivalent to the global window object in browser environments.

                                          Type #

                                          Window & globalThis

                                          Did you find what you needed?

                                          Privacy policy