-
-
Notifications
You must be signed in to change notification settings - Fork 261
IOptionalBrowserSettings
David Ortner edited this page Oct 17, 2025
·
25 revisions
IOptionalBrowserSettings represents the optional settings of the Browser.
interface IOptionalBrowserSettingsimport { Browser } from "happy-dom";
const browser = new Browser({
settings: {
navigator: : {
userAgent: "Mozilla/5.0 (X11; Linux x64) AppleWebKit/537.36 (KHTML, like Gecko) HappyDOM/2.0.0"
}
}
});| Property | Type | Default | Description |
|---|---|---|---|
| enableJavaScriptEvaluation? | boolean | false | Enables JavaScript evaluation and script loading. A VM Context is not an isolated environment, and if you run untrusted JavaScript code you are at risk of RCE (Remote Code Execution) attacks. Read more about risks and recommended security precautions here. |
| suppressInsecureJavaScriptEnvironmentWarning? | boolean | false | Suppresses the warning that is printed when the JavaScript execution environment is insecure. |
| disableJavaScriptFileLoading? | boolean | false | Disables JavaScript file loading. |
| handleDisabledFileLoadingAsSuccess? | boolean | false | Set to "true" to trigger a load event instead of an error event when file loading is disabled. |
| disableCSSFileLoading? | boolean | false | Disables CSS file loading. |
| disableComputedStyleRendering? | boolean | false | Disables computed style rendering. |
| 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. |
| navigation.beforeContentCallback? | (window: BrowserWindow) => void | Triggered before content is loaded into the document. | |
| 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. |
| device.prefersReducedMotion? | string | "no-preference" | Prefers reduced motion. |
| device.forcedColors? | string | "none" | Forced colors ("active" or "none") |
| fetch.disableSameOriginPolicy? | boolean | false | Disables the same-origin policy for fetch requests. |
| fetch.disableStrictSSL? | boolean | false | Disables validation of certificates, allowing for self-signed certificates to be used. |
| fetch.interceptor? | IFetchInterceptor | Intercept fetch requests and responses using hooks | |
| fetch.requestHeaders? | IFetchRequestHeaders[] | Sets custom request headers for matching URLs | |
| fetch.virtualServers? | IVirtualServer[] | Simulate local HTTP servers that serves files from the file system | |
| debug.traceWaitUntilComplete? | number | -1 | Sets a time in ms for when waitUntilComplete() should timeout and reject the promise with an error containing which tasks that have not completed and the stack traces for them. |
| viewport? | IOptionalBrowserPageViewport | Default viewport settings. |
Help Packages