@hyperfrontend/testing/browserbrowser
Stand-ins for the browser surfaces a test environment cannot supply: windows that message each other across origins, and a ResizeObserver the test drives.
Usage
Unlike /dom, importing this entry changes nothing on the global, and none of it needs jsdom. Each stand-in is typed as the browser interface it replaces, so it goes straight into code that expects a Window without a cast.
Windows that message each other
createWindowPair returns two windows wired the way a page and the frame or popup it opened are. Posting to one delivers to that window's listeners with the other window as the event's source and the other window's origin as its origin:
import { expect, it, waitUntil } from '@hyperfrontend/testing'
import { createWindowPair } from '@hyperfrontend/testing/browser'
import { connect } from './connect'
it('connects a host and its frame', async () => {
const [host, frame] = createWindowPair({ origins: ['https://host.test', 'https://frame.test'] })
const hostSide = connect({ listenOn: host, peer: frame })
const frameSide = connect({ listenOn: frame, peer: host })
await waitUntil(() => hostSide.isOpen() && frameSide.isOpen())
expect(frame.posted()).toEqual([expect.objectContaining({ type: 'HELLO' })])
})
| Behaviour | What the pair does |
|---|---|
| Delivery | On a later timer task, as a browser delivers, which fake timers control. Pass delivery: 'sync' to deliver inside the call instead. |
| Target origin | A post whose target origin is neither * nor the receiving window's origin is dropped. / stands for the sender's own origin. |
| Copying | The message is copied with structuredClone. A transfer list is ignored, so a posted buffer stays readable in the recorded call. |
| Recording | Every post is recorded, delivered or not: postMessage is a mock function, and posted lists the messages. |
createFakeWindow is a single window with no counterpart: it records what is posted to it, and receive dispatches a message to its listeners as if another origin had sent it.
ResizeObserver
installResizeObserver puts a ResizeObserver on the global and returns the controller that sends its notifications:
const observers = installResizeObserver()
const panel = mountPanel(container)
observers.resize(container, { width: 320, height: 200 })
expect(panel.layout()).toBe('compact')
Observers behave like real ones, observing, unobserving and disconnecting, and each entry carries the content rectangle and every box size. A callback runs only when the test calls resize, never on its own, not even for the initial notification a browser sends when observation starts. resizeLate also reaches observers that have stopped watching the element, the way a notification already queued when observation stopped still arrives, for testing code that must ignore one. The stub is installed as a stubbed global, so jest.restoreAllMocks removes it.
API Reference§
ƒ Functions
Use it as the target a piece of code posts to, asserting on
posted, or as the window a piece of code listens on, feeding it messages with receive.Parameters
| Name | Type | Description |
|---|---|---|
§options | FakeWindowOptions | The window's origin.(default: {}) |
Returns
FakeWindowWindow.Example
Feeding a listener a message from another origin
const host = createFakeWindow({ origin: 'https://host.test' })
const stop = listenForCommands(host)
host.receive({ type: 'PING' }, { origin: 'https://feature.test' })
expect(host.posted()).toEqual([{ type: 'PONG' }])Posting to one window delivers to that window's own listeners, with the other window as the event's
source and the other window's origin as its origin, exactly as a browser reports a message one window sent another. A post whose target origin is neither * nor the receiving window's origin is dropped, as a browser drops it, with / standing for the sender's own origin. The message is copied with structuredClone, so the receiver never shares an object with the sender; a transfer list is ignored, which leaves the posted buffers readable for assertions. By default delivery waits for a later timer task, which fake timers control.Parameters
| Name | Type | Description |
|---|---|---|
§options | WindowPairOptions | The windows' origins and when a post is delivered.(default: {}) |
Returns
unknownWindow.Example
Connecting two brokers across a frame boundary
const [host, frame] = createWindowPair({ origins: ['https://host.test', 'https://frame.test'] })
const hostBroker = createBroker({ window: host })
const frameBroker = createBroker({ window: frame })
hostBroker.addChannel('frame', frame).connect()
frameBroker.addChannel('host', host).connect()
await waitUntil(() => hostBroker.isConnected())ResizeObserver on the global whose notifications the test sends, and returns the controller that sends them. jsdom has no layout engine and so no
ResizeObserver. Observers created through this one behave like the real constructor's, observing, unobserving and disconnecting, but a callback runs only when the test calls resize, never on its own: not even the initial notification a browser sends after observe. resizeLate delivers to observers that have stopped watching the element too, the way a notification already queued when observation stopped still arrives, for code that must ignore one. The stub is installed like a stubbed global, so jest.restoreAllMocks and the runner's restoreMocks option remove it.Returns
ResizeObserverControllerExample
Driving a component that follows its container's width
const observers = installResizeObserver()
const panel = mountPanel(container)
observers.resize(container, { width: 320, height: 200 })
expect(panel.layout()).toBe('compact')◈ Interfaces
Window is expected.Properties
postMessage:MockFnRecords every message posted to this window, and delivers it when the window is linked.readonly origin:stringThe origin this window's own documents run in, compared against a post's target origin.onabort:( this: GlobalEventHandlers, ev: UIEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/abort_event)onanimationcancel:( this: GlobalEventHandlers, ev: AnimationEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationcancel_event)onanimationend:( this: GlobalEventHandlers, ev: AnimationEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationend_event)onanimationiteration:( this: GlobalEventHandlers, ev: AnimationEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationiteration_event)onanimationstart:( this: GlobalEventHandlers, ev: AnimationEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/animationstart_event)onauxclick:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/auxclick_event)onbeforeinput:( this: GlobalEventHandlers, ev: InputEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/beforeinput_event)onbeforematch:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/beforematch_event)onbeforetoggle:( this: GlobalEventHandlers, ev: ToggleEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/beforetoggle_event)onblur:( this: GlobalEventHandlers, ev: FocusEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/blur_event)oncancel:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLDialogElement/cancel_event)oncanplay:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/canplay_event)oncanplaythrough:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/canplaythrough_event)onchange:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/change_event)onclick:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/click_event)onclose:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLDialogElement/close_event)oncontextlost:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/contextlost_event)oncontextrestored:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/contextrestored_event)oncopy:( this: GlobalEventHandlers, ev: ClipboardEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/copy_event)oncuechange:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLTrackElement/cuechange_event)oncut:( this: GlobalEventHandlers, ev: ClipboardEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/cut_event)ondblclick:( this: GlobalEventHandlers, ev: MouseEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/dblclick_event)ondrag:( this: GlobalEventHandlers, ev: DragEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/drag_event)ondragend:( this: GlobalEventHandlers, ev: DragEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragend_event)ondragenter:( this: GlobalEventHandlers, ev: DragEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragenter_event)ondragleave:( this: GlobalEventHandlers, ev: DragEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragleave_event)ondragover:( this: GlobalEventHandlers, ev: DragEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragover_event)ondragstart:( this: GlobalEventHandlers, ev: DragEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/dragstart_event)ondrop:( this: GlobalEventHandlers, ev: DragEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/drop_event)ondurationchange:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/durationchange_event)onemptied:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/emptied_event)onended:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event)onerror:OnErrorEventHandlerNonNull[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event)onfocus:( this: GlobalEventHandlers, ev: FocusEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event)onformdata:( this: GlobalEventHandlers, ev: FormDataEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event)ongotpointercapture:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/gotpointercapture_event)oninput:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/input_event)oninvalid:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/invalid_event)onkeydown:( this: GlobalEventHandlers, ev: KeyboardEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/keydown_event)onkeyup:( this: GlobalEventHandlers, ev: KeyboardEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/keyup_event)onload:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/load_event)onloadeddata:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/loadeddata_event)onloadedmetadata:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/loadedmetadata_event)onloadstart:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/loadstart_event)onlostpointercapture:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/lostpointercapture_event)onmousedown:( this: GlobalEventHandlers, ev: MouseEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mousedown_event)onmouseenter:( this: GlobalEventHandlers, ev: MouseEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseenter_event)onmouseleave:( this: GlobalEventHandlers, ev: MouseEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseleave_event)onmousemove:( this: GlobalEventHandlers, ev: MouseEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mousemove_event)onmouseout:( this: GlobalEventHandlers, ev: MouseEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseout_event)onmouseover:( this: GlobalEventHandlers, ev: MouseEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseover_event)onmouseup:( this: GlobalEventHandlers, ev: MouseEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/mouseup_event)onpaste:( this: GlobalEventHandlers, ev: ClipboardEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/paste_event)onpause:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/pause_event)onplay:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/play_event)onplaying:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/playing_event)onpointercancel:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointercancel_event)onpointerdown:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerdown_event)onpointerenter:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerenter_event)onpointerleave:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerleave_event)onpointermove:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointermove_event)onpointerout:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerout_event)onpointerover:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerover_event)onpointerrawupdate:( this: GlobalEventHandlers, ev: Event) => anyAvailable only in secure contexts. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerrawupdate_event)
onpointerup:( this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/pointerup_event)onprogress:( this: GlobalEventHandlers, ev: ProgressEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/progress_event)onratechange:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ratechange_event)onreset:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/reset_event)onresize:( this: GlobalEventHandlers, ev: UIEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLVideoElement/resize_event)onscroll:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/scroll_event)onscrollend:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/scrollend_event)onsecuritypolicyviolation:( this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/securitypolicyviolation_event)onseeked:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/seeked_event)onseeking:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/seeking_event)onselect:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLInputElement/select_event)onselectionchange:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/selectionchange_event)onselectstart:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/selectstart_event)onslotchange:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLSlotElement/slotchange_event)onstalled:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/stalled_event)onsubmit:( this: GlobalEventHandlers, ev: SubmitEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/submit_event)onsuspend:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/suspend_event)ontimeupdate:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/timeupdate_event)ontoggle:( this: GlobalEventHandlers, ev: ToggleEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/toggle_event)ontouchcancel?:( this: GlobalEventHandlers, ev: TouchEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/touchcancel_event)ontouchend?:( this: GlobalEventHandlers, ev: TouchEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/touchend_event)ontouchmove?:( this: GlobalEventHandlers, ev: TouchEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/touchmove_event)ontouchstart?:( this: GlobalEventHandlers, ev: TouchEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/touchstart_event)ontransitioncancel:( this: GlobalEventHandlers, ev: TransitionEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitioncancel_event)ontransitionend:( this: GlobalEventHandlers, ev: TransitionEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitionend_event)ontransitionrun:( this: GlobalEventHandlers, ev: TransitionEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitionrun_event)ontransitionstart:( this: GlobalEventHandlers, ev: TransitionEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/transitionstart_event)onvolumechange:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/volumechange_event)onwaiting:( this: GlobalEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/waiting_event)onwheel:( this: GlobalEventHandlers, ev: WheelEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/wheel_event)readonly closed:booleanThe Window.closed read-only property indicates whether the referenced window is closed or not. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/closed)
readonly customElements:CustomElementRegistryThe customElements read-only property of the Window interface returns a reference to the CustomElementRegistry object, which can be used to register new custom elements and get information about previously registered custom elements. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/customElements)
readonly devicePixelRatio:numberThe devicePixelRatio of Window interface returns the ratio of the resolution in _physical pixels_ to the resolution in _CSS pixels_ for the current display device. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/devicePixelRatio)
readonly document:Documentwindow.document returns a reference to the document contained in the window. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/document)
readonly event:EventThe read-only Window property event returns the Event which is currently being handled by the site's code.readonly external:ExternalThe external property of the Window API returns an instance of the External interface, which was intended to contain functions related to adding external search providers to the browser.readonly frameElement:ElementThe Window.frameElement property returns the element (such as iframe or object) in which the window is embedded. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/frameElement)
readonly frames:WindowReturns the window itself, which is an array-like object, listing the direct sub-frames of the current window. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/frames)
readonly history:HistoryThe Window.history read-only property returns a reference to the History object, which provides an interface for manipulating the browser _session history_ (pages visited in the tab or frame that the current page is loaded in). [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/history)
readonly innerHeight:numberThe read-only innerHeight property of the including the height of the horizontal scroll bar, if present. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/innerHeight)
readonly innerWidth:numberThe read-only Window property innerWidth returns the interior width of the window in pixels (that is, the width of the window's layout viewport). [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/innerWidth)
readonly length:numberReturns the number of frames (either frame or A number. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/length)
get set location:LocationThe Window.location read-only property returns a Location object with information about the current location of the document. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/location)
readonly locationbar:BarPropReturns the locationbar object. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/locationbar)
name:stringThe Window.name property gets/sets the name of the window's browsing context. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/name)
ondevicemotion:( this: Window, ev: DeviceMotionEvent) => anyAvailable only in secure contexts. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/devicemotion_event)
ondeviceorientation:( this: Window, ev: DeviceOrientationEvent) => anyAvailable only in secure contexts. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientation_event)
ondeviceorientationabsolute:( this: Window, ev: DeviceOrientationEvent) => anyAvailable only in secure contexts. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event)
opener:anyThe Window interface's opener property returns a reference to the window that opened the window, either with Window.open, or by navigating a link with a target attribute. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/opener)
readonly orientation:numberReturns the orientation in degrees (in 90-degree increments) of the viewport relative to the device's natural orientation.readonly originAgentCluster:booleanThe originAgentCluster read-only property of the Window interface returns true if this window belongs to an _origin-keyed agent cluster_: this means that the operating system has provided dedicated resources (for example an operating system process) to this window's origin that are not shared with windows from other origins. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/originAgentCluster)
readonly outerHeight:numberThe Window.outerHeight read-only property returns the height in pixels of the whole browser window, including any sidebar, window chrome, and window-resizing borders/handles. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/outerHeight)
readonly outerWidth:numberWindow.outerWidth read-only property returns the width of the outside of the browser window. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/outerWidth)
readonly pageXOffset:number[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/scrollX)readonly pageYOffset:number[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/scrollY)readonly parent:WindowThe Window.parent property is a reference to the parent of the current window or subframe. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/parent)
readonly personalbar:BarPropReturns the personalbar object. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/personalbar)
readonly screen:ScreenThe Window property screen returns a reference to the screen object associated with the window. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/screen)
readonly screenLeft:numberThe Window.screenLeft read-only property returns the horizontal distance, in CSS pixels, from the left border of the user's browser viewport to the left side of the screen. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/screenLeft)
readonly screenTop:numberThe Window.screenTop read-only property returns the vertical distance, in CSS pixels, from the top border of the user's browser viewport to the top side of the screen. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/screenTop)
readonly screenX:numberThe Window.screenX read-only property returns the horizontal distance, in CSS pixels, of the left border of the user's browser viewport to the left side of the screen. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/screenX)
readonly screenY:numberThe Window.screenY read-only property returns the vertical distance, in CSS pixels, of the top border of the user's browser viewport to the top edge of the screen. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/screenY)
readonly scrollX:numberThe read-only scrollX property of the Window interface returns the number of pixels by which the document is currently scrolled horizontally. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/scrollX)
readonly scrollY:numberThe read-only scrollY property of the Window interface returns the number of pixels by which the document is currently scrolled vertically. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/scrollY)
readonly scrollbars:BarPropReturns the scrollbars object. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/scrollbars)
readonly self:Window & unknownThe Window.self read-only property returns the window itself, as a WindowProxy. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/self)
readonly speechSynthesis:SpeechSynthesisThe speechSynthesis read-only property of the Window object returns a SpeechSynthesis object, which is the entry point into using Web Speech API speech synthesis functionality. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/speechSynthesis)
readonly statusbar:BarPropReturns the statusbar object. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/statusbar)
readonly toolbar:BarPropReturns the toolbar object. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/toolbar)
readonly top:WindowReturns a reference to the topmost window in the window hierarchy. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/top)
readonly visualViewport:VisualViewportThe visualViewport read-only property of the Window interface returns a VisualViewport object representing the visual viewport for a given window, or null if current document is not fully active. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/visualViewport)
readonly window:Window & unknownThe window property of a Window object points to the window object itself. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/window)
onafterprint:( this: WindowEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/afterprint_event)onbeforeprint:( this: WindowEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/beforeprint_event)onbeforeunload:( this: WindowEventHandlers, ev: BeforeUnloadEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/beforeunload_event)ongamepadconnected:( this: WindowEventHandlers, ev: GamepadEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/gamepadconnected_event)ongamepaddisconnected:( this: WindowEventHandlers, ev: GamepadEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/gamepaddisconnected_event)onhashchange:( this: WindowEventHandlers, ev: HashChangeEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/hashchange_event)onlanguagechange:( this: WindowEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/languagechange_event)onmessage:( this: WindowEventHandlers, ev: MessageEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/message_event)onmessageerror:( this: WindowEventHandlers, ev: MessageEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/messageerror_event)onoffline:( this: WindowEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/offline_event)ononline:( this: WindowEventHandlers, ev: Event) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/online_event)onpagehide:( this: WindowEventHandlers, ev: PageTransitionEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/pagehide_event)onpagereveal:( this: WindowEventHandlers, ev: PageRevealEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/pagereveal_event)onpageshow:( this: WindowEventHandlers, ev: PageTransitionEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/pageshow_event)onpageswap:( this: WindowEventHandlers, ev: PageSwapEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/pageswap_event)onpopstate:( this: WindowEventHandlers, ev: PopStateEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/popstate_event)onrejectionhandled:( this: WindowEventHandlers, ev: PromiseRejectionEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/rejectionhandled_event)onstorage:( this: WindowEventHandlers, ev: StorageEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/storage_event)onunhandledrejection:( this: WindowEventHandlers, ev: PromiseRejectionEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/unhandledrejection_event)readonly localStorage:Storage[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/localStorage)readonly caches:CacheStorageAvailable only in secure contexts. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/caches)
readonly crossOriginIsolated:boolean[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/crossOriginIsolated)readonly indexedDB:IDBFactory[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/indexedDB)readonly isSecureContext:boolean[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/isSecureContext)readonly performance:Performance[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/performance)Methods
atob( data: string): stringParameters
| Name | Type | Description |
|---|---|---|
§data | string |
atob( data: string): stringParameters
| Name | Type | Description |
|---|---|---|
§data | string |
blur( ): voidWindow.blur() method does nothing.btoa( data: string): stringParameters
| Name | Type | Description |
|---|---|---|
§data | string |
btoa( data: string): stringParameters
| Name | Type | Description |
|---|---|---|
§data | string |
cancelAnimationFrame( handle: number): voidParameters
| Name | Type | Description |
|---|---|---|
§handle | number |
cancelAnimationFrame( handle: number): voidParameters
| Name | Type | Description |
|---|---|---|
§handle | number |
captureEvents( ): voidWindow.captureEvents() method does nothing.clearInterval( id: number): voidParameters
| Name | Type | Description |
|---|---|---|
§id | number |
clearInterval( id: number): voidParameters
| Name | Type | Description |
|---|---|---|
§id | number |
clearTimeout( id: number): voidParameters
| Name | Type | Description |
|---|---|---|
§id | number |
clearTimeout( id: number): voidParameters
| Name | Type | Description |
|---|---|---|
§id | number |
close( ): voidWindow.close() method closes the current window, or the window on which it was called. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/close)
confirm( message?: string): booleanwindow.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/confirm)
Parameters
| Name | Type | Description |
|---|---|---|
§message? | string |
createImageBitmap( image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise< ImageBitmap>createImageBitmap( image: ImageBitmapSource, options?: ImageBitmapOptions): Promise< ImageBitmap>dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
dispatchEvent( event: Event): booleandispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
focus( ): void[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/focus)
getComputedStyle( elt: Element, pseudoElt?: string): CSSStyleDeclarationWindow.getComputedStyle() method returns an object containing the values of all CSS properties of an element, after applying active stylesheets and resolving any basic computation those values may contain. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/getComputedStyle)
getSelection( ): SelectiongetSelection() method of the Window interface returns the Selection object associated with the window's document, representing the range of text selected by the user or the current position of the caret. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/getSelection)
matchMedia( query: string): MediaQueryListmatchMedia() method returns a new MediaQueryList object that can then be used to determine if the document matches the media query string, as well as to monitor the document to detect when it matches (or stops matching) that media query. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/matchMedia)
Parameters
| Name | Type | Description |
|---|---|---|
§query | string |
messageListenerCount( ): numbermessage listeners are registered.open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/open)
posted( ): unknown[ ]print( ): void[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/print)
prompt( message?: string, _default?: string): stringwindow.prompt() instructs the browser to display a dialog with an optional message prompting the user to input some text, and to wait until the user either submits the text or cancels the dialog. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/prompt)
queueMicrotask( callback: VoidFunction): voidParameters
| Name | Type | Description |
|---|---|---|
§callback | VoidFunction |
queueMicrotask( callback: VoidFunction): voidParameters
| Name | Type | Description |
|---|---|---|
§callback | VoidFunction |
receive( data: unknown, from?: MessageSender): voidmessage event to this window's listeners now, as if another window had posted it.Parameters
| Name | Type | Description |
|---|---|---|
§data | unknown | |
§from? | MessageSender |
releaseEvents( ): voidreportError( e: any): voidParameters
| Name | Type | Description |
|---|---|---|
§e | any |
reportError( e: any): voidParameters
| Name | Type | Description |
|---|---|---|
§e | any |
requestAnimationFrame( callback: FrameRequestCallback): numberParameters
| Name | Type | Description |
|---|---|---|
§callback | FrameRequestCallback |
requestAnimationFrame( callback: FrameRequestCallback): numberParameters
| Name | Type | Description |
|---|---|---|
§callback | FrameRequestCallback |
requestIdleCallback( callback: IdleRequestCallback, options?: IdleRequestOptions): numberwindow.requestIdleCallback() method queues a function to be called during a browser's idle periods. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/requestIdleCallback)
setInterval( handler: TimerHandler, timeout?: number, ...arguments: any[ ]): numbersetTimeout( handler: TimerHandler, timeout?: number, ...arguments: any[ ]): numberstop( ): voidwindow.stop() stops further resource loading in the current browsing context, equivalent to the stop button in the browser. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/stop)
structuredClone< T>( value: T, options?: StructuredSerializeOptions): T◆ Types
ResizeObserver that installResizeObserver put on the global.