Skip to content

IBrowserSettings

David Ortner edited this page Nov 6, 2024 · 8 revisions

IBrowserSettings represents the settings of the browser.

Signature

interface IBrowserSettings

Example

import { Browser } from "happy-dom";

const browser = new Browser();
browser.settings.navigator.userAgent =
	"Mozilla/5.0 (X11; Linux x64) AppleWebKit/537.36 (KHTML, like Gecko) HappyDOM/2.0.0";

Properties

Property Type Default Description
disableJavaScriptEvaluation boolean false Disables JavaScript evaluation.
disableJavaScriptFileLoading boolean false Disables JavaScript file loading.
disableCSSFileLoading boolean false Disables CSS file loading.
disableComputedStyleRendering boolean false Disables computed style rendering.
handleDisabledFileLoadingAsSuccess boolean false Set to "true" to trigger a load event instead of an error event when file loading is disabled.
errorCapture BrowserErrorCaptureEnum "tryAndCatch" Error capturing policy.
navigation.disableMainFrameNavigation boolean false Disables navigation to other pages in the main frame or a page.
navigation.disableChildFrameNavigation boolean false Disables navigation to other pages in child frames (such as iframes).
navigation.disableChildPageNavigation boolean false Disables navigation to other pages in child pages (such as popup windows).
navigation.disableFallbackToSetURL boolean false Disables the fallback to setting the URL when navigating to a page is disabled or when inside a detached browser frame.
navigation.crossOriginPolicy BrowserNavigationCrossOriginPolicyEnum "anyOrigin" Sets the policy for cross-origin navigation.
navigator.userAgent string User agent based on the Node.js process. "HappyDOM/{version}" is added to the string to be able to detect that the browser is Happy DOM.
navigator.maxTouchPoints number 0 Max touch points.
timer.maxTimeout number -1 (disabled) Sets the maximum time a timeout is allowed to have. This can improve load times if the environment has long running timers.
timer.maxIntervalTime number -1 (disabled) Sets the maximum time an interval is allowed to have. This can improve load times if the environment has long running intervals.
timer.maxIntervalIterations number -1 (disabled) Sets the maximum number of interval iterations. This can unblock environments from completing loading.
timer.preventTimerLoops boolean false Set to "true" to prevent timer loops (e.g. a setTimeout() calling itself to initialize a new setTimeout()). This has a performance impact as the call stack of each timer will be stored to match against.
device.prefersColorScheme string "light" Prefers color scheme.
device.mediaType string "screen" Media type.
fetch.disableSameOriginPolicy boolean false Disables the same-origin policy for fetch requests.
Clone this wiki locally