Web Core Utilities
Web core utilities are browser-specific functions designed for client-side walkerOS implementations. These utilities handle DOM interactions, browser information, storage, sessions, and web-based communication.
Installation
Import web utilities from the @walkeros/web-core package:
DOM Utilities
getAttribute
getAttribute(element: Element, name: string): string retrieves attribute
values from DOM elements with enhanced handling.
Attribute Parsing
splitAttribute
splitAttribute(str: string, separator?: string): string[] splits attribute
strings using specified separators.
splitKeyVal
splitKeyVal(str: string): [string, string] splits key-value pairs from
attribute strings.
parseInlineConfig
parseInlineConfig(str: string): Record<string, unknown> parses inline
configuration strings from HTML attributes.
Browser Information
getLanguage
getLanguage(navigatorRef: Navigator): string | undefined extracts the user's
preferred language.
getTimezone
getTimezone(): string | undefined gets the user's timezone from the Intl API.
getScreenSize
getScreenSize(windowRef: Window): string returns the window's screen
dimensions.
Element Visibility
isVisible
isVisible(element: HTMLElement): boolean checks if an element is visible to
the user.
This function considers:
- Element display and visibility styles
- Element position within viewport
- Parent element visibility
- Intersection with the visible area
Storage Management
Storage Operations
storageRead
storageRead(key: string, storage?: StorageType): WalkerOS.PropertyType reads
data from browser storage with automatic type conversion.
storageWrite
storageWrite(key: string, value: WalkerOS.PropertyType, maxAgeInMinutes?: number, storage?: StorageType, domain?: string): WalkerOS.PropertyType
writes data to storage with expiration and domain options.
storageDelete
storageDelete(key: string, storage?: StorageType) removes data from storage.
Session Management
sessionStart
sessionStart(config?: SessionConfig): WalkerOS.SessionData | void initializes
and manages user sessions with automatic renewal and tracking.
Session data includes:
id- Unique session identifierstart- Session start timestampisNew- Whether this is a new sessioncount- Number of events in sessiondevice- Device identifierstorage- Whether storage is available
Advanced Session Functions
sessionStorage- Session-specific storage operationssessionWindow- Window/tab session management
Web Communication
sendWeb
sendWeb<T>(url: string, data?: SendDataValue, options?: SendWebOptionsDynamic<T>): SendWebReturn<T>
sends data using various web transport methods.
Transport-Specific Functions
sendWebAsFetch
sendWebAsFetch(url: string, data?: SendDataValue, options?: SendWebOptionsFetch): Promise<SendResponse>
uses the modern Fetch API with advanced options.
sendWebAsBeacon
sendWebAsBeacon(url: string, data?: SendDataValue): SendResponse uses the
Beacon API for reliable data transmission, especially during page unload.
sendWebAsXhr
sendWebAsXhr(url: string, data?: SendDataValue, options?: SendWebOptions): SendResponse
uses XMLHttpRequest for synchronous communication.
Web Hashing
getHashWeb
getHashWeb(str: string, length?: number): Promise<string> generates SHA-256
hashes using the Web Crypto API.
Configuration Types
SendWebOptions
SessionConfig
StorageType
Usage Notes
- Consent Required: Browser information functions may require user consent depending on privacy regulations
- Storage Fallbacks: Storage functions gracefully handle unavailable storage with fallbacks
- Transport Selection: Choose transport based on use case:
fetch- Modern, flexible, supports responsesbeacon- Reliable during page unload, small payloadsxhr- Synchronous when needed, broader browser support
- Performance: Session and storage operations are optimized for minimal performance impact
For platform-agnostic utilities, see Core Utilities.