isBrowser
The isBrowser
function determines whether the current JavaScript runtime environment is a browser.
Import
import { isBrowser } from "@tai-kun/surrealdb/utils";
Usage
function isBrowser(): boolean;
Arguments
None.
Return Value
Returns true
if the environment is a browser, false
otherwise.
Example
The following example demonstrates how to determine whether the environment is a browser:
import { isBrowser } from "@tai-kun/surrealdb/utils";
if (isBrowser()) { document;}
Explanation
This function checks if the global variable document
is defined. If it is, the environment is considered a browser. Using window
for detection is unreliable because some server-side runtimes, such as Deno, add a window
object to the global scope. This would lead to a false positive. The Remix web framework refers to this concept as a Document Guard.