Socket
Socket
Sign inDemoInstall

happy-dom

Package Overview
Dependencies
3
Maintainers
1
Versions
555
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 13.8.6 to 13.9.0

2

cjs/fetch/AbortController.d.ts

@@ -18,4 +18,4 @@ import AbortSignal from './AbortSignal.cjs';

*/
abort(reason?: string): void;
abort(reason?: Error): void;
}
//# sourceMappingURL=AbortController.d.ts.map

@@ -11,3 +11,3 @@ import EventTarget from '../event/EventTarget.cjs';

readonly aborted: boolean;
readonly reason: string | null;
readonly reason: Error | null;
onabort: ((this: AbortSignal, event: Event) => void) | null;

@@ -23,4 +23,8 @@ /**

*/
[PropertySymbol.abort](reason?: string): void;
[PropertySymbol.abort](reason?: Error): void;
/**
* Throws an "AbortError" if the signal has been aborted.
*/
throwIfAborted(): void;
/**
* Returns an AbortSignal instance that has been set as aborted.

@@ -31,4 +35,4 @@ *

*/
static abort(reason?: string): AbortSignal;
static abort(reason?: Error): AbortSignal;
}
//# sourceMappingURL=AbortSignal.d.ts.map

@@ -83,3 +83,3 @@ import * as PropertySymbol from '../../PropertySymbol.js';

let responseText;
const timeout = frame.window.setTimeout(() => abortController.abort('Request timed out.'), goToOptions?.timeout ?? 30000);
const timeout = frame.window.setTimeout(() => abortController.abort(new Error('Request timed out.')), goToOptions?.timeout ?? 30000);
const finalize = () => {

@@ -86,0 +86,0 @@ frame.window.clearTimeout(timeout);

@@ -18,4 +18,4 @@ import AbortSignal from './AbortSignal.js';

*/
abort(reason?: string): void;
abort(reason?: Error): void;
}
//# sourceMappingURL=AbortController.d.ts.map

@@ -11,3 +11,3 @@ import EventTarget from '../event/EventTarget.js';

readonly aborted: boolean;
readonly reason: string | null;
readonly reason: Error | null;
onabort: ((this: AbortSignal, event: Event) => void) | null;

@@ -23,4 +23,8 @@ /**

*/
[PropertySymbol.abort](reason?: string): void;
[PropertySymbol.abort](reason?: Error): void;
/**
* Throws an "AbortError" if the signal has been aborted.
*/
throwIfAborted(): void;
/**
* Returns an AbortSignal instance that has been set as aborted.

@@ -31,4 +35,4 @@ *

*/
static abort(reason?: string): AbortSignal;
static abort(reason?: Error): AbortSignal;
}
//# sourceMappingURL=AbortSignal.d.ts.map
import EventTarget from '../event/EventTarget.js';
import * as PropertySymbol from '../PropertySymbol.js';
import Event from '../event/Event.js';
import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum.js';
import DOMException from '../exception/DOMException.js';
/**

@@ -31,5 +33,5 @@ * AbortSignal.

}
if (reason) {
this.reason = reason;
}
this.reason =
reason ||
new DOMException('signal is aborted without reason', DOMExceptionNameEnum.abortError);
this.aborted = true;

@@ -39,2 +41,10 @@ this.dispatchEvent(new Event('abort'));

/**
* Throws an "AbortError" if the signal has been aborted.
*/
throwIfAborted() {
if (this.aborted) {
throw this.reason;
}
}
/**
* Returns an AbortSignal instance that has been set as aborted.

@@ -47,5 +57,5 @@ *

const signal = new AbortSignal();
if (reason) {
signal.reason = reason;
}
signal.reason =
reason ||
new DOMException('signal is aborted without reason', DOMExceptionNameEnum.abortError);
signal.aborted = true;

@@ -52,0 +62,0 @@ return signal;

@@ -633,3 +633,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

abort(reason) {
const error = new DOMException('The operation was aborted.' + (reason ? ' ' + reason : ''), DOMExceptionNameEnum.abortError);
const error = new DOMException('The operation was aborted.' + (reason ? ' ' + reason.toString() : ''), DOMExceptionNameEnum.abortError);
if (this.nodeRequest && !this.nodeRequest.destroyed) {

@@ -636,0 +636,0 @@ this.nodeRequest.destroy(error);

@@ -1,1 +0,1 @@

export default { version: '13.8.6' };
export default { version: '13.9.0' };
{
"name": "happy-dom",
"version": "13.8.6",
"version": "13.9.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/capricorn86/happy-dom",

![Happy DOM Logo](https://github.com/capricorn86/happy-dom/raw/master/docs/happy-dom-logo.jpg)
# About
A JavaScript implementation of a web browser without its graphical user interface.
[Happy DOM](https://github.com/capricorn86/happy-dom) is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG [DOM](https://dom.spec.whatwg.org/) and [HTML](https://html.spec.whatwg.org/multipage/).
## DOM Features
The goal of [Happy DOM](https://github.com/capricorn86/happy-dom) is to emulate enough of a web browser to be useful for testing, scraping web sites and server-side rendering.
[Happy DOM](https://github.com/capricorn86/happy-dom) focuses heavily on performance and can be used as an alternative to [JSDOM](https://github.com/jsdom/jsdom).
### DOM Features
- Custom Elements (Web Components)
- Shadow Root (Shadow DOM)
- Declarative Shadow DOM

@@ -23,85 +15,20 @@

- Fetch
- Fetch API
And much more..
### Works With
## Documentation
- [Google LitHTML](https://lit-html.polymer-project.org)
[Documentation](https://github.com/capricorn86/happy-dom/wiki/) | [Getting Started](https://github.com/capricorn86/happy-dom/wiki/Getting-started) | [Setup as Test Environment](https://github.com/capricorn86/happy-dom/wiki/Setup-as-Test-Environment) | [GitHub](https://github.com/capricorn86/happy-dom/)
- [Google LitElement](https://lit-element.polymer-project.org)
## Works With
- [React](https://reactjs.org)
[Vitest](https://vitest.dev/) | [Bun](https://bun.sh) | [Jest](https://jestjs.io/) | [Testing Library](https://testing-library.com/) | [Google LitElement](https://lit.dev/) | [Vue](https://vuejs.org/) | [React](https://reactjs.org) | [Svelte](https://svelte.dev/) | [Angular](https://angular.io/)
- [Angular](https://angular.io/)
## Module Systems
- [Vue](https://vuejs.org/)
[ESM](https://nodejs.org/api/esm.html#introduction) | [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules)
### Module Systems
## Performance
- [ESM](https://nodejs.org/api/esm.html#introduction)
- [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules)
# Installation
```bash
npm install happy-dom
```
# Usage
Happy DOM can be used as a simulated [Browser](https://github.com/capricorn86/happy-dom/wiki/Browser) or by using the [Window](https://github.com/capricorn86/happy-dom/wiki/Window) class directly to quickly setup up a DOM.
## Window
```javascript
import { Window } from 'happy-dom';
const window = new Window({ url: 'https://localhost:8080' });
const document = window.document;
document.body.innerHTML = '<div class="container"></div>';
const container = document.querySelector('.container');
const button = document.createElement('button');
container.appendChild(button);
// Outputs "<div class="container"><button></button></div>"
console.log(document.body.innerHTML);
// Closes the window
await window.happyDOM.close();
```
## Browser
```javascript
import { Browser, BrowserErrorCaptureEnum } from 'happy-dom';
const browser = new Browser({ settings: { errorCapture: BrowserErrorCaptureEnum.processLevel } });
const page = browser.newPage();
// Navigates page
await page.goto('https://github.com/capricorn86');
// Clicks on link
page.mainFrame.document.querySelector('a[href*="capricorn86/happy-dom"]').click();
// Waits for all operations on the page to complete (fetch, timers etc.)
await page.waitUntilComplete();
// Outputs "GitHub - capricorn86/happy-dom: Happy DOM..."
console.log(page.mainFrame.document.title);
// Closes the browser
await browser.close();
```
# Documentation
Read more about how to use Happy DOM in our [Wiki](https://github.com/capricorn86/happy-dom/wiki).
# Performance
| Operation | JSDOM | Happy DOM |

@@ -114,27 +41,4 @@ | ------------------------------------ | ------- | --------- |

| querySelectorAll('tagname') | 4.9 ms | 0.7 ms |
| querySelectorAll('.class') | 6.4 ms | 3.7 ms |
| querySelectorAll('[attribute]') | 4.0 ms | 1.7 ms |
| querySelectorAll('[class~="name"]') | 5.5 ms | 2.9 ms |
| querySelectorAll(':nth-child(2n+1)') | 10.4 ms | 3.8 ms |
See how the test was done [here](https://github.com/capricorn86/happy-dom-performance-test)
# Jest
Happy DOM provide with a package called [@happy-dom/jest-environment](https://github.com/capricorn86/happy-dom/tree/master/packages/jest-environment) that makes it possible to use Happy DOM with [Jest](https://jestjs.io/).
# Vitest
[Vitest](https://github.com/vitest-dev/vitest) supports Happy DOM out of the box.
# Global Registration
Happy DOM provide with a package called [@happy-dom/global-registrator](https://github.com/capricorn86/happy-dom/tree/master/packages/global-registrator) that can register Happy DOM globally. It makes it possible to use Happy DOM for testing in a Node environment.
# Sister Projects
[<img alt="Happy Conventional Commit" width="120px" src="https://raw.githubusercontent.com/capricorn86/happy-conventional-commit/main/docs/logo_thumbnail.jpg" />](https://github.com/capricorn86/happy-conventional-commit)
# Sponsors
[<img alt="RTVision" width="120px" src="https://avatars.githubusercontent.com/u/8292810?s=200&v=4" />](https://rtvision.com)
See how the test was done [here](https://github.com/capricorn86/happy-dom-performance-test)

@@ -128,3 +128,3 @@ import IBrowserFrame from '../types/IBrowserFrame.js';

const timeout = frame.window.setTimeout(
() => abortController.abort('Request timed out.'),
() => abortController.abort(new Error('Request timed out.')),
goToOptions?.timeout ?? 30000

@@ -131,0 +131,0 @@ );

@@ -24,5 +24,5 @@ import AbortSignal from './AbortSignal.js';

*/
public abort(reason?: string): void {
public abort(reason?: Error): void {
this.signal[PropertySymbol.abort](reason);
}
}
import EventTarget from '../event/EventTarget.js';
import * as PropertySymbol from '../PropertySymbol.js';
import Event from '../event/Event.js';
import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum.js';
import DOMException from '../exception/DOMException.js';

@@ -12,3 +14,3 @@ /**

public readonly aborted: boolean = false;
public readonly reason: string | null = null;
public readonly reason: Error | null = null;
public onabort: ((this: AbortSignal, event: Event) => void) | null = null;

@@ -28,9 +30,9 @@

*/
public [PropertySymbol.abort](reason?: string): void {
public [PropertySymbol.abort](reason?: Error): void {
if (this.aborted) {
return;
}
if (reason) {
(<string>this.reason) = reason;
}
(<Error>this.reason) =
reason ||
new DOMException('signal is aborted without reason', DOMExceptionNameEnum.abortError);
(<boolean>this.aborted) = true;

@@ -41,2 +43,11 @@ this.dispatchEvent(new Event('abort'));

/**
* Throws an "AbortError" if the signal has been aborted.
*/
public throwIfAborted(): void {
if (this.aborted) {
throw this.reason;
}
}
/**
* Returns an AbortSignal instance that has been set as aborted.

@@ -47,7 +58,7 @@ *

*/
public static abort(reason?: string): AbortSignal {
public static abort(reason?: Error): AbortSignal {
const signal = new AbortSignal();
if (reason) {
(<string>signal.reason) = reason;
}
(<Error>signal.reason) =
reason ||
new DOMException('signal is aborted without reason', DOMExceptionNameEnum.abortError);
(<boolean>signal.aborted) = true;

@@ -54,0 +65,0 @@ return signal;

@@ -802,5 +802,5 @@ import IRequestInit from './types/IRequestInit.js';

*/
private abort(reason?: string): void {
private abort(reason?: Error): void {
const error = new DOMException(
'The operation was aborted.' + (reason ? ' ' + reason : ''),
'The operation was aborted.' + (reason ? ' ' + reason.toString() : ''),
DOMExceptionNameEnum.abortError

@@ -807,0 +807,0 @@ );

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc