{"id":13548074,"url":"https://github.com/lukechilds/browser-env","last_synced_at":"2025-04-12T23:41:32.624Z","repository":{"id":45517417,"uuid":"59607491","full_name":"lukechilds/browser-env","owner":"lukechilds","description":"Simulates a global browser environment using jsdom","archived":false,"fork":false,"pushed_at":"2020-02-02T00:28:00.000Z","size":106,"stargazers_count":174,"open_issues_count":11,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T00:33:18.209Z","etag":null,"topics":["jsdom","testing","window-namespace"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukechilds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-24T20:46:01.000Z","updated_at":"2024-09-10T11:03:31.000Z","dependencies_parsed_at":"2022-09-01T19:13:09.380Z","dependency_job_id":null,"html_url":"https://github.com/lukechilds/browser-env","commit_stats":null,"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechilds%2Fbrowser-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechilds%2Fbrowser-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechilds%2Fbrowser-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechilds%2Fbrowser-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukechilds","download_url":"https://codeload.github.com/lukechilds/browser-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647254,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsdom","testing","window-namespace"],"created_at":"2024-08-01T12:01:05.404Z","updated_at":"2025-04-12T23:41:32.595Z","avatar_url":"https://github.com/lukechilds.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# browser-env\n\n\u003e Simulates a global browser environment using [`jsdom`](https://github.com/tmpvar/jsdom).\n\n[![Build Status](https://travis-ci.org/lukechilds/browser-env.svg?branch=master)](https://travis-ci.org/lukechilds/browser-env)\n[![Coverage Status](https://coveralls.io/repos/github/lukechilds/browser-env/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/browser-env?branch=master)\n[![npm](https://img.shields.io/npm/dm/browser-env.svg)](https://www.npmjs.com/package/browser-env)\n[![npm](https://img.shields.io/npm/v/browser-env.svg)](https://www.npmjs.com/package/browser-env)\n\nThis allows you to run browser modules in Node.js 6 or newer with minimal or no effort. Can also be used to test browser modules with any Node.js test framework. Please note, only the DOM is simulated, if you want to run a module that requires more advanced browser features (like `localStorage`), you'll need to polyfill that seperately.\n\nUse `browser-env@2` to support older Node.js versions.\n\n\u003e ❗️**Important note**\n\u003e\n\u003e This module adds properties from the `jsdom` window namespace to the Node.js global namespace. This is explicitly [recommended against](https://github.com/tmpvar/jsdom/wiki/Don't-stuff-jsdom-globals-onto-the-Node-global) by `jsdom`. There may be scenarios where this is ok for your use case but please read through the linked wiki page and make sure you understand the caveats. If you don't need the browser environment enabled globally, [`window`](https://github.com/lukechilds/window) may be a better solution.\n\n## Install\n\n```shell\nnpm install --save browser-env\n```\n\nOr if you're just using for testing you'll probably want:\n\n```shell\nnpm install --save-dev browser-env\n```\n\n## Usage\n\n```js\n// Init\nrequire('browser-env')();\n\n// Now you have access to a browser like environment in Node.js:\n\ntypeof window;\n// 'object'\n\ntypeof document;\n// 'object'\n\nvar div = document.createElement('div');\n// HTMLDivElement\n\ndiv instanceof HTMLElement\n// true\n```\n\nBy default everything in the `jsdom` window namespace is tacked on to the Node.js global namespace (excluding existing Node.js properties e.g `console`, `setTimout`). If you want to trim this down you can pass an array of required properties:\n\n```js\n// Init\nrequire('browser-env')(['window']);\n\ntypeof window;\n// 'object'\n\ntypeof document;\n// 'undefined'\n```\n\nYou can also pass a config object straight through to `jsdom`. This can be done with or without specifying required properties.\n\n```js\nrequire('browser-env')(['window'], { userAgent: 'My User Agent' });\n\n// or\n\nrequire('browser-env')({ userAgent: 'My User Agent' });\n```\n\nYou can of course also assign to a function:\n\n```js\nvar browserEnv = require('browser-env');\nbrowserEnv();\n\n// or\n\nimport browserEnv from 'browser-env';\nbrowserEnv();\n```\n\n`browser-env` can also be preloaded at node startup as:\n\n```sh\nnode -r browser-env/register test.js\n```\n\n## Related\n\n- [`window`](https://github.com/lukechilds/window) - Exports a jsdom window object\n\n## License\n\nMIT © Luke Childs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukechilds%2Fbrowser-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukechilds%2Fbrowser-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukechilds%2Fbrowser-env/lists"}