
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600Ć Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Ć faster than humans.
eslint-plugin-no-typeof-window-undefined
Advanced tools
ESLint rule to avoid typeof window === 'undefined' for SSR check
ESLint rule that helps avoid typeof window === "undefined"
check and fix it to typeof document === "undefined"
instead.
It's recommended to use document
over window
because server runtimes like Deno have a global window available.
pnpm add -D eslint eslint-plugin-no-typeof-window-undefined
Add to .eslintrc
{
"extends": ["plugin:no-typeof-window-undefined/recommended"]
}
ā
Set in the recommended
configuration
š§ Automatically fixable by the --fix
CLI option.\
Name | Description | š¼ | š§ |
---|---|---|---|
no-typeof-window-undefined | Improve SSR/Browser environment check by using typeof document !== "undefined" . | ā | š§ |
Because the same JavaScript code can run in the browser as well as the server, sometimes you need to have a part of your code that only runs in one context or the other:
if (typeof window === "undefined") {
// running in a server environment
} else {
// running in a browser environment
}
This works fine in a Node.js environment, however, Deno actually supports window! So if you really want to check whether you're running in the browser, it's better to check for document instead:
if (typeof document === "undefined") {
// running in a server environment
} else {
// running in a browser environment
}
This will work for all JS environments (Node.js, Deno, Workers, etc.).
FAQs
ESLint rule to avoid typeof window === 'undefined' for SSR check
The npm package eslint-plugin-no-typeof-window-undefined receives a total of 15,725 weekly downloads. As such, eslint-plugin-no-typeof-window-undefined popularity was classified as popular.
We found that eslint-plugin-no-typeof-window-undefined demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Ć faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.