Spec-Zone.ru › Deno 2

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


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

  • https://developer.mozilla.org/en-US/docs/Web/API/Window/alert


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

  • https://developer.mozilla.org/en-US/docs/Web/API/Window/close


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

  • https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm


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

  • https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt


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

func: VoidFunction

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,
options?: StructuredSerializeOptions,
): 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

signal: AbortSignal
readonly

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

prototype: AbortController
readonly

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: ((
this: AbortSignal,
ev: Event,
) => any) | null

Methods

addEventListener<K extends keyof AbortSignalEventMap>(
type: K,
listener: (
this: AbortSignal,
ev: AbortSignalEventMap[K],
) => any
,
options?: boolean | AddEventListenerOptions,
): void
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void
removeEventListener<K extends keyof AbortSignalEventMap>(
type: K,
listener: (
this: AbortSignal,
ev: AbortSignalEventMap[K],
) => any
,
options?: boolean | EventListenerOptions,
): void
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void
throwIfAborted(): 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

prototype: AbortSignal
readonly

Methods

abort(reason?: any): AbortSignal
any(signals: AbortSignal[]): AbortSignal
timeout(milliseconds: number): AbortSignal

interface AbortSignalEventMap

Properties

abort: Event

interface CSSRule

unstable

A single CSS rule of a CSSStyleSheet, as returned from its cssRules property. Available only when the --unstable-raw-imports flag is enabled.

Note: cssText is the verbatim text of one top-level rule of the style sheet; Deno does not implement a full CSS object model.

Properties

cssText: string
readonly

variable CSSRule

unstable

Properties

prototype: CSSRule
readonly

interface CSSStyleSheet

unstable

A style sheet backing a CSS module script. This is what a import sheet from "./styles.css" with { type: "css" } import evaluates to. Available only when the --unstable-raw-imports flag is enabled.

Deno has no DOM, so a sheet can't be adopted anywhere; the implementation is backed by the raw CSS text.

Note: cssRules returns a frozen array of CSSRule instead of a live CSSRuleList.

Properties

cssRules: readonly CSSRule[]
readonly

Methods

replace(text: string): Promise<CSSStyleSheet>
replaceSync(text: string): void

variable CSSStyleSheet

unstable

Properties

prototype: CSSStyleSheet
readonly

interface DOMException

extends Error

Properties

name: string
readonly
message: string
readonly
code: number
deprecated
readonly
INDEX_SIZE_ERR: 1
readonly
DOMSTRING_SIZE_ERR: 2
readonly
HIERARCHY_REQUEST_ERR: 3
readonly
WRONG_DOCUMENT_ERR: 4
readonly
INVALID_CHARACTER_ERR: 5
readonly
NO_DATA_ALLOWED_ERR: 6
readonly
NO_MODIFICATION_ALLOWED_ERR: 7
readonly
NOT_FOUND_ERR: 8
readonly
NOT_SUPPORTED_ERR: 9
readonly
INUSE_ATTRIBUTE_ERR: 10
readonly
INVALID_STATE_ERR: 11
readonly
SYNTAX_ERR: 12
readonly
INVALID_MODIFICATION_ERR: 13
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
INVALID_NODE_TYPE_ERR: 24
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

prototype: DOMException
readonly
INDEX_SIZE_ERR: 1
readonly
DOMSTRING_SIZE_ERR: 2
readonly
HIERARCHY_REQUEST_ERR: 3
readonly
WRONG_DOCUMENT_ERR: 4
readonly
INVALID_CHARACTER_ERR: 5
readonly
NO_DATA_ALLOWED_ERR: 6
readonly
NO_MODIFICATION_ALLOWED_ERR: 7
readonly
NOT_FOUND_ERR: 8
readonly
NOT_SUPPORTED_ERR: 9
readonly
INUSE_ATTRIBUTE_ERR: 10
readonly
INVALID_STATE_ERR: 11
readonly
SYNTAX_ERR: 12
readonly
INVALID_MODIFICATION_ERR: 13
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
INVALID_NODE_TYPE_ERR: 24
readonly
DATA_CLONE_ERR: 25
readonly

interface DomIterable

Type Parameters

K
V

Methods

keys(): IterableIterator<K>
values(): IterableIterator<V>
entries(): IterableIterator<[K, V]>
[[Symbol.iterator]](): IterableIterator<[K, V]>
forEach(
callback: (
value: V,
key: K,
parent: this,
) => void
,
thisArg?: any,
): void

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 ErrorConstructor

Properties

stackTraceLimit: number

Methods

captureStackTrace(
error: Object,
constructor?: Function,
): void

See https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions.


interface ImageData

Properties

width: number
readonly
height: number
readonly
data: ImageDataArray
readonly
pixelFormat: ImageDataPixelFormat
readonly
colorSpace: PredefinedColorSpace
readonly

variable ImageData

The constructor object for ImageData, used to create an object holding the raw pixel data of a rectangular image region, either zero-filled for the given dimensions or wrapping an existing pixel array.

Properties

prototype: ImageData
readonly

interface ImageDataSettings

Properties

colorSpace: PredefinedColorSpace
readonly
optional
pixelFormat: ImageDataPixelFormat
readonly
optional

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

ancestorOrigins: DOMStringList
readonly

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.

search: string

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

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

prototype: Location
readonly

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

Examples

// Check available CPU cores
console.log(`Available CPU cores: ${navigator.hardwareConcurrency}`);

// Check user agent
console.log(`User agent: ${navigator.userAgent}`);

// Check language settings
console.log(`Language: ${navigator.language}`);

Properties

gpu: GPU
readonly
hardwareConcurrency: number
readonly
userAgent: string
readonly
language: string
readonly
languages: string[]
readonly
platform: string
readonly
userAgentData: NavigatorUAData
readonly

variable Navigator

Constructor for Navigator objects.

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

Properties

prototype: Navigator
readonly

interface NavigatorUABrandVersion

A brand and version pair describing a user agent, as returned by NavigatorUAData.

Properties

brand: string
readonly
version: string
readonly

interface NavigatorUAData

Gives access to information about the runtime's user agent, exposed via Navigator.userAgentData. This is the User-Agent Client Hints API.

Properties

brands: NavigatorUABrandVersion[]
readonly

A list of the runtime's brand and major version.

mobile: boolean
readonly

Whether the runtime reports itself as a mobile device. Always false in Deno.

platform: string
readonly

The platform the runtime is running on (e.g. "Linux", "macOS", "Windows").

Methods

getHighEntropyValues(hints: string[]): Promise<UADataValues>

Resolves with the requested high-entropy values. Unrecognized hints are ignored. The low-entropy values (brands, mobile, platform) are always included.

toJSON(): UALowEntropyJSON

Returns a JSON representation of the low-entropy values.

variable NavigatorUAData

Constructor for NavigatorUAData objects.

Note: This constructor cannot be used to create new NavigatorUAData instances in Deno.

Properties

prototype: NavigatorUAData
readonly

interface QuotaExceededError

extends DOMException

Represents an error when a quota has been exceeded.

Properties

quota: number | null
readonly
requested: number | null
readonly

variable QuotaExceededError

The constructor object for QuotaExceededError, used to construct an error thrown when an operation would exceed an enforced quota.

Properties

prototype: QuotaExceededError
readonly

interface QuotaExceededErrorOptions

Properties

quota: number
optional
requested: number
optional

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

transfer: Transferable[]
optional

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


interface UADataValues

The values returned by NavigatorUAData.getHighEntropyValues.

Properties

brands: NavigatorUABrandVersion[]
readonly
optional
mobile: boolean
readonly
optional
platform: string
readonly
optional
architecture: string
readonly
optional
bitness: string
readonly
optional
formFactors: string[]
readonly
optional
fullVersionList: NavigatorUABrandVersion[]
readonly
optional
model: string
readonly
optional
platformVersion: string
readonly
optional
uaFullVersion: string
readonly
optional
wow64: boolean
readonly
optional

interface UALowEntropyJSON

The low-entropy values returned by NavigatorUAData.toJSON.

Properties

brands: NavigatorUABrandVersion[]
readonly
mobile: boolean
readonly
platform: string
readonly

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


interface VoidFunction

Call Signatures

(): void

interface WebTransport

MDN Reference

Properties

closed: Promise<WebTransportCloseInfo>
readonly

MDN Reference

datagrams: WebTransportDatagramDuplexStream
readonly

MDN Reference

incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalStream>
readonly

MDN Reference

incomingUnidirectionalStreams: ReadableStream<WebTransportReceiveStream>
readonly

MDN Reference

ready: Promise<void>
readonly

MDN Reference

Methods

close(closeInfo?: WebTransportCloseInfo): void

MDN Reference

createBidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WebTransportBidirectionalStream>

MDN Reference

createUnidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WebTransportSendStream>

MDN Reference

createSendGroup(): WebTransportSendGroup

MDN Reference

variable WebTransport

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

Properties

prototype: WebTransport

interface WebTransportBidirectionalStream

MDN Reference

Properties

readable: WebTransportReceiveStream
readonly

MDN Reference

writable: WebTransportSendStream
readonly

MDN Reference

variable WebTransportBidirectionalStream

The constructor object for WebTransportBidirectionalStream.

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

Properties

prototype: WebTransportBidirectionalStream

interface WebTransportCloseInfo

Properties

closeCode: number
optional
reason: string
optional

interface WebTransportDatagramDuplexStream

MDN Reference

Properties

incomingHighWaterMark: number

MDN Reference

incomingMaxAge: number | null

MDN Reference

maxDatagramSize: number
readonly

MDN Reference

outgoingHighWaterMark: number

MDN Reference

outgoingMaxAge: number | null

MDN Reference

readable: WebTransportReceiveStream
readonly

MDN Reference

writable: WebTransportSendStream
readonly

MDN Reference

variable WebTransportDatagramDuplexStream

The constructor object for WebTransportDatagramDuplexStream.

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

Properties

prototype: WebTransportDatagramDuplexStream

interface WebTransportError

extends DOMException

MDN Reference

Properties

source: WebTransportErrorSource
readonly

MDN Reference

streamErrorCode: number | null
readonly

MDN Reference

variable WebTransportError

The constructor object for WebTransportError, used to construct an error describing a failure of a WebTransport session or one of its streams.

Properties

prototype: WebTransportError

interface WebTransportErrorOptions

Properties

source: WebTransportErrorSource
optional
streamErrorCode: number | null
optional

interface WebTransportHash

Properties

algorithm: string
optional
value: BufferSource
optional

interface WebTransportOptions

Properties

allowPooling: boolean
optional
congestionControl: WebTransportCongestionControl
optional
requireUnreliable: boolean
optional
serverCertificateHashes: WebTransportHash[]
optional

interface WebTransportReceiveStream

extends ReadableStream<Uint8Array>

MDN Reference

Methods

getStats(): Promise<WebTransportReceiveStreamStats>

MDN Reference

variable WebTransportReceiveStream

The constructor object for WebTransportReceiveStream.

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

Properties

prototype: WebTransportReceiveStream

interface WebTransportReceiveStreamStats

Properties

bytesReceived: number
bytesRead: number

interface WebTransportSendGroup

MDN Reference

Methods

getStats(): Promise<WebTransportSendStreamStats>

MDN Reference

variable WebTransportSendGroup

The constructor object for WebTransportSendGroup.

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

Properties

prototype: WebTransportSendGroup

interface WebTransportSendStream

extends WritableStream<Uint8Array>

MDN Reference

Properties

sendOrder: number

MDN Reference

sendGroup: WebTransportSendGroup
optional

MDN Reference

Methods

getStats(): Promise<WebTransportSendStreamStats>

MDN Reference

getWriter(): WebTransportWriter

MDN Reference

variable WebTransportSendStream

The constructor object for WebTransportSendStream.

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

Properties

prototype: WebTransportSendStream

interface WebTransportSendStreamOptions

Properties

sendGroup: WebTransportSendGroup
optional
sendOrder: number
optional
waitUntilAvailable: boolean
optional

interface WebTransportSendStreamStats

Properties

bytesWritten: number
bytesSent: number
bytesAcknowledged: number

interface WebTransportWriter

extends WritableStreamDefaultWriter<Uint8Array>

MDN Reference

Methods

atomicWrite(chunk: any): Promise<undefined>

MDN Reference

variable WebTransportWriter

The constructor object for WebTransportWriter.

Instances are obtained from a WebTransportSendStream rather than constructed directly.

Properties

prototype: WebTransportWriter

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,
ev: ErrorEvent,
) => any) | null
onload: ((
this: Window,
ev: Event,
) => any) | null
onbeforeunload: ((
this: Window,
ev: Event,
) => any) | null
onunload: ((
this: Window,
ev: Event,
) => any) | null
onunhandledrejection: ((
this: Window,
ev: PromiseRejectionEvent,
) => any) | null
onrejectionhandled: ((
this: Window,
ev: PromiseRejectionEvent,
) => any) | null
close: () => void
closed: boolean
readonly
alert: (message?: string) => void
confirm: (message?: string) => boolean
prompt: (
message?: string,
defaultValue?: string,
) => string | null
Deno: Deno
Navigator: Navigator
navigator: Navigator
Location: Location
location: Location
localStorage: Storage
sessionStorage: Storage
caches: CacheStorage
name: string

Methods

addEventListener<K extends keyof WindowEventMap>(
type: K,
listener: (
this: Window,
ev: WindowEventMap[K],
) => any
,
options?: boolean | AddEventListenerOptions,
): void
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void
removeEventListener<K extends keyof WindowEventMap>(
type: K,
listener: (
this: Window,
ev: WindowEventMap[K],
) => any
,
options?: boolean | EventListenerOptions,
): void
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
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

interface WindowEventMap

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

This interface provides type safety for event handlers by associating event names with their proper event types.

Properties

error: ErrorEvent
unhandledrejection: PromiseRejectionEvent
rejectionhandled: PromiseRejectionEvent

type alias AllowSharedBufferSource

Definition

ArrayBufferView | ArrayBufferLike

type alias BufferSource

Definition

ArrayBufferView<ArrayBuffer> | ArrayBuffer

type alias ImageDataArray

Definition

Uint8ClampedArray<ArrayBuffer> | Float16Array<ArrayBuffer>

type alias ImageDataPixelFormat

Definition

"rgba-unorm8" | "rgba-float16"

type alias PredefinedColorSpace

Definition

"srgb" | "display-p3"

type alias WebTransportCongestionControl

Definition

"default"
| "low-latency"
| "throughput"

type alias WebTransportErrorSource

Definition

"session" | "stream"

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

Location

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 navigator

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

Examples

// Log information about the runtime environment
console.log(`Hardware concurrency: ${navigator.hardwareConcurrency}`);
console.log(`User agent: ${navigator.userAgent}`);

Type

Navigator

variable self

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

Type

Window & globalThis

© 2018–2025 the Deno authors
Licensed under the MIT License.
https://docs.deno.com/api/web/platform

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API