Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
enable-window-document
Advanced tools
Enables "window" and "document" globals so browser code does not throw errors in Node. Built with JSDOM.
window
and document
This package enables the window
and document
globals for executing most browser JS. For fully simulating the browser, see the enable-browser-mode
plugin.
/* [CommonJS] */
require('enable-window-document');
- or -
/* [ES6] */
import 'enable-window-document'
No variable assignment required, just call it! The variables are stored on the global
object so you can refer to them as you normally would in browser JS.
Won't work:
console.log(document.createElement('a'));
> ReferenceError: document is not defined
Works like a charm:
require('enable-window-document');
console.log(document.createElement('a'));
> HTMLAnchorElement {Symbol(impl): HTMLAnchorElementImpl}
This package simply creates a blank JSDOM with a few lines of code, and stores the global window
and document
variables, which point to the empty DOM:
let JSDOM = require('jsdom'),
DOM = new JSDOM.JSDOM(`<html><body></body></html>`, {
url: 'https://localhost',
resources: 'usable',
runScripts: global.UNSAFE_MODE
? 'dangerously'
: 'outside-only'
});
global.window = DOM.window,
global.document = window.document;
The url
param is set for compatibility reasons related to localStorage
, and resources
and runScripts
are set by default so that external scripts work as expected.
By default, JSDOM is called with runScripts: 'outside-only'
. Set global.UNSAFE_MODE
before your require('enable-window-document')
call to enable dangerous mode and execute external scripts when added to DOM.
FAQs
Enables "window" and "document" globals so browser code does not throw errors in Node. Built with JSDOM.
We found that enable-window-document 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.