@hyperfrontend/testing/browser

browser

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' })])
})
BehaviourWhat the pair does
DeliveryOn a later timer task, as a browser delivers, which fake timers control. Pass delivery: 'sync' to deliver inside the call instead.
Target originA post whose target origin is neither * nor the receiving window's origin is dropped. / stands for the sender's own origin.
CopyingThe message is copied with structuredClone. A transfer list is ignored, so a posted buffer stays readable in the recorded call.
RecordingEvery 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

§function

createFakeWindow(options: FakeWindowOptions): FakeWindow

Creates a window that records what is posted to it and delivers nothing on its own.
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
NameTypeDescription
§options
FakeWindowOptionsThe window's origin.(default: {})
Returns
FakeWindow
The window, typed as a Window.
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' }])
§function

createWindowPair(options: WindowPairOptions): unknown

Creates two windows that can message each other, as a page and the frame or popup it opened.
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
NameTypeDescription
§options
WindowPairOptionsThe windows' origins and when a post is delivered.(default: {})
Returns
unknown
The two windows, each typed as a Window.
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())
§function

installResizeObserver(): ResizeObserverController

Puts a 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
Example

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

§interface

FakeWindow

A stand-in for a browser window as cross-window messaging sees it, accepted wherever a Window is expected.
Properties
§postMessage:MockFnRecords every message posted to this window, and delivers it when the window is linked.
§addEventListener:MockFnRegisters a listener, as a window does. Calls are recorded.
§removeEventListener:MockFnRemoves a listener, as a window does. Calls are recorded.
§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)
§oncontextmenu:(this: GlobalEventHandlers, ev: PointerEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/contextmenu_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)
§onkeypress:(this: GlobalEventHandlers, ev: KeyboardEvent) => any
§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)
§onwebkitanimationend:(this: GlobalEventHandlers, ev: Event) => any
§onwebkitanimationiteration:(this: GlobalEventHandlers, ev: Event) => any
§onwebkitanimationstart:(this: GlobalEventHandlers, ev: Event) => any
§onwebkittransitionend:(this: GlobalEventHandlers, ev: Event) => any
§onwheel:(this: GlobalEventHandlers, ev: WheelEvent) => any[MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/wheel_event)
§readonly clientInformation:Navigator
§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 cookieStore:CookieStoreThe cookieStore read-only property of the Window interface returns a reference to the CookieStore object for the current document context.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/cookieStore)
§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)
§readonly menubar:BarPropReturns the menubar object.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/menubar)
§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)
§readonly navigator:NavigatorThe Window.navigator read-only property returns a reference to the Navigator object, which has methods and properties about the application running the script.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/navigator)
§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)
§onorientationchange:(this: Window, ev: Event) => any
§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)
§status:stringThe status property of the bar at the bottom of the browser window.
§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)
§onunload:(this: WindowEventHandlers, ev: Event) => any
§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 crypto:Crypto[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/crypto)
§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)
§readonly sessionStorage:Storage[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/sessionStorage)
Methods
§alert(message?: any): void
window.alert() instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/alert)

Parameters

NameTypeDescription
§message?
any
§atob(data: string): string
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob)

Parameters

NameTypeDescription
§data
string
atob(data: string): string
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob)

Parameters

NameTypeDescription
§data
string
§blur(): void
The Window.blur() method does nothing.
§btoa(data: string): string
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa)

Parameters

NameTypeDescription
§data
string
btoa(data: string): string
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa)

Parameters

NameTypeDescription
§data
string
§cancelAnimationFrame(handle: number): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/cancelAnimationFrame)

Parameters

NameTypeDescription
§handle
number
cancelAnimationFrame(handle: number): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/cancelAnimationFrame)

Parameters

NameTypeDescription
§handle
number
§cancelIdleCallback(handle: number): void
The window.cancelIdleCallback() method cancels a callback previously scheduled with window.requestIdleCallback().
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/cancelIdleCallback)

Parameters

NameTypeDescription
§handle
number
§captureEvents(): void
The Window.captureEvents() method does nothing.
§clearInterval(id: number): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/clearInterval)

Parameters

NameTypeDescription
§id
number
clearInterval(id: number): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/clearInterval)

Parameters

NameTypeDescription
§id
number
§clearTimeout(id: number): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/clearTimeout)

Parameters

NameTypeDescription
§id
number
clearTimeout(id: number): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/clearTimeout)

Parameters

NameTypeDescription
§id
number
§close(): void
The Window.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): boolean
window.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

NameTypeDescription
§message?
string
§createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/createImageBitmap)

Parameters

NameTypeDescription
§image
ImageBitmapSource
§options?
ImageBitmapOptions
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>

Parameters

NameTypeDescription
§image
ImageBitmapSource
§sx
number
§sy
number
§sw
number
§sh
number
§options?
ImageBitmapOptions
createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/createImageBitmap)

Parameters

NameTypeDescription
§image
ImageBitmapSource
§options?
ImageBitmapOptions
createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>

Parameters

NameTypeDescription
§image
ImageBitmapSource
§sx
number
§sy
number
§sw
number
§sh
number
§options?
ImageBitmapOptions
§dispatchEvent(event: Event): boolean
The 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)

Parameters

NameTypeDescription
§event
Event
dispatchEvent(event: Event): boolean
The 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)

Parameters

NameTypeDescription
§event
Event
§fetch(input: URL | RequestInfo, init?: RequestInit): Promise<Response>
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

Parameters

NameTypeDescription
§input
URL | RequestInfo
§init?
RequestInit
fetch(input: URL | RequestInfo, init?: RequestInit): Promise<Response>
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch)

Parameters

NameTypeDescription
§input
URL | RequestInfo
§init?
RequestInit
§focus(): void
Makes a request to bring the window to the front.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/focus)
§getComputedStyle(elt: Element, pseudoElt?: string): CSSStyleDeclaration
The Window.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)

Parameters

NameTypeDescription
§elt
Element
§pseudoElt?
string
§getSelection(): Selection
The getSelection() 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): MediaQueryList
The Window interface's matchMedia() 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

NameTypeDescription
§query
string
§messageListenerCount(): number
How many message listeners are registered.
§moveBy(x: number, y: number): void
The moveBy() method of the Window interface moves the current window by a specified amount.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/moveBy)

Parameters

NameTypeDescription
number
number
§moveTo(x: number, y: number): void
The moveTo() method of the Window interface moves the current window to the specified coordinates.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/moveTo)

Parameters

NameTypeDescription
number
number
§open(url?: string | URL, target?: string, features?: string): Window
The 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)

Parameters

NameTypeDescription
§url?
string | URL
§target?
string
§features?
string
§posted(): unknown[]
The data of every message posted to this window, in order, whether or not it was delivered.
§print(): void
Opens the print dialog to print the current document.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/print)
§prompt(message?: string, _default?: string): string
window.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)

Parameters

NameTypeDescription
§message?
string
§_default?
string
§queueMicrotask(callback: VoidFunction): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/queueMicrotask)

Parameters

NameTypeDescription
§callback
VoidFunction
queueMicrotask(callback: VoidFunction): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/queueMicrotask)

Parameters

NameTypeDescription
§callback
VoidFunction
§receive(data: unknown, from?: MessageSender): void
Dispatches a message event to this window's listeners now, as if another window had posted it.

Parameters

NameTypeDescription
§data
unknown
§from?
MessageSender
§releaseEvents(): void
Releases the window from trapping events of a specific type.
§reportError(e: any): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/reportError)

Parameters

NameTypeDescription
any
reportError(e: any): void
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/reportError)

Parameters

NameTypeDescription
any
§requestAnimationFrame(callback: FrameRequestCallback): number
[MDN Reference](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame)

Parameters

NameTypeDescription
§callback
FrameRequestCallback
requestAnimationFrame(callback: FrameRequestCallback): number
[MDN Reference](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame)

Parameters

NameTypeDescription
§callback
FrameRequestCallback
§requestIdleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): number
The window.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)

Parameters

NameTypeDescription
§callback
IdleRequestCallback
§options?
IdleRequestOptions
§resizeBy(x: number, y: number): void
The Window.resizeBy() method resizes the current window by a specified amount.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/resizeBy)

Parameters

NameTypeDescription
number
number
§resizeTo(width: number, height: number): void
The Window.resizeTo() method dynamically resizes the window.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/resizeTo)

Parameters

NameTypeDescription
§width
number
§height
number
§scroll(options?: ScrollToOptions): void
The Window.scroll() method scrolls the window to a particular place in the document.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/scroll)

Parameters

NameTypeDescription
§options?
ScrollToOptions
scroll(x: number, y: number): void

Parameters

NameTypeDescription
number
number
§scrollBy(options?: ScrollToOptions): void
The Window.scrollBy() method scrolls the document in the window by the given amount.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/scrollBy)

Parameters

NameTypeDescription
§options?
ScrollToOptions
scrollBy(x: number, y: number): void

Parameters

NameTypeDescription
number
number
§scrollTo(options?: ScrollToOptions): void
Window.scrollTo() scrolls to a particular set of coordinates in the document.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/scrollTo)

Parameters

NameTypeDescription
§options?
ScrollToOptions
scrollTo(x: number, y: number): void

Parameters

NameTypeDescription
number
number
§setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/setInterval)

Parameters

NameTypeDescription
§handler
TimerHandler
§timeout?
number
§...arguments
any[]
setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/setInterval)

Parameters

NameTypeDescription
§handler
TimerHandler
§timeout?
number
§...arguments
any[]
§setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/setTimeout)

Parameters

NameTypeDescription
§handler
TimerHandler
§timeout?
number
§...arguments
any[]
setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/setTimeout)

Parameters

NameTypeDescription
§handler
TimerHandler
§timeout?
number
§...arguments
any[]
§stop(): void
The window.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
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/structuredClone)

Parameters

NameTypeDescription
§value
T
§options?
StructuredSerializeOptions
structuredClone<T>(value: T, options?: StructuredSerializeOptions): T
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/structuredClone)

Parameters

NameTypeDescription
§value
T
§options?
StructuredSerializeOptions

◆ Types

§type

FakeWindowOptions

How a standalone fake window presents itself.
§type

MessageSender

Where a message dispatched with receive claims to come from.
§type

ObservedSize

A size to report for an observed element, in CSS pixels.
§type

ResizeObserverController

Drives the ResizeObserver that installResizeObserver put on the global.
§type

WindowPairOptions

How a linked pair of fake windows behaves.