Skip to content

Browser

The Browser module provides a collection of utilities for interacting with web browser APIs. It includes functions for managing fullscreen mode, detecting connection status, handling DOM events, controlling page scrolling, and accessing native features like sharing. It also offers methods to check user preferences and device capabilities.

Overview

exitFullscreen

typescript
exitFullscreen(): void

Exits fullscreen mode, if supported by the browser.

getLanguage

typescript
getLanguage(): string

Returns the user's preferred browser language.

getTheme

typescript
getTheme(): "light" | "dark"

Gets the user's preferred theme (light or dark).

isCookieEnabled

typescript
isCookieEnabled(): boolean

Checks if cookies are enabled in the browser.

isFullscreenEnabled

typescript
isFullscreenEnabled(): boolean

Checks if the fullscreen API is available.

isOnline

typescript
isOnline(): boolean

Checks if the browser is connected to the internet.

isShareable

typescript
isShareable(): boolean

Checks if the native sharing API is available.

isTabActive

typescript
isTabActive(): boolean

Checks if the browser tab is active (visible).

isTouchDevice

typescript
isTouchDevice(): boolean

Checks if the device supports touch events.

on

typescript
on<K extends keyof HTMLElementEventMap>(target: HTMLElement | Document | Window, type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void

Adds an event listener to a DOM element.

onOffline

typescript
onOffline(listener: () => void): void

Adds a listener for the offline event.

onOnline

typescript
onOnline(listener: () => void): void

Adds a listener for the online event.

onVisibilityChange

typescript
onVisibilityChange(listener: () => void): void

Adds a listener for tab visibility changes.

requestFullscreen

typescript
requestFullscreen(element?: HTMLElement): void

Requests an element to enter fullscreen mode.

scrollToElement

typescript
scrollToElement(target: string | HTMLElement, options?: ScrollIntoViewOptions): void

Smoothly scrolls to a target element on the page.

scrollToTop

typescript
scrollToTop(options?: ScrollToOptions): void

Smoothly scrolls to the top of the page.

share

typescript
share(data: ShareData): Promise<void>

Uses the native API to share data such as title, text, URL, or files.

Released under the MIT License.