Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: capricorn86/happy-dom
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v13.8.6
Choose a base ref
...
head repository: capricorn86/happy-dom
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9d6d1f39aeb2cbfce914277ce22264ee88290582
Choose a head ref
  • 17 commits
  • 15 files changed
  • 1 contributor

Commits on Mar 16, 2024

  1. chore: [#1317] Improves documentation and adds sponsors to README.md

    capricorn86 committed Mar 16, 2024
    Copy the full SHA
    e02ef46 View commit details
  2. Merge pull request #1318 from capricorn86/1317-add-sponsors-to-readmemd

    chore: [#1317] Improves documentation and adds sponsors to README.md
    capricorn86 authored Mar 16, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    35d8db5 View commit details
  3. chore: [#1317] Improves documentation and adds sponsors to README.md

    capricorn86 committed Mar 16, 2024
    Copy the full SHA
    b95bccc View commit details
  4. Merge branch 'master' into 1317-add-sponsors-to-readmemd

    capricorn86 authored Mar 16, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    49ae94f View commit details
  5. Merge pull request #1319 from capricorn86/1317-add-sponsors-to-readmemd

    chore: [#1317] Improves documentation and adds sponsors to README.md
    capricorn86 authored Mar 16, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    44db3aa View commit details
  6. chore: [#1317] Improves documentation and adds sponsors to README.md

    capricorn86 committed Mar 16, 2024
    Copy the full SHA
    e554b2d View commit details
  7. Merge branch 'master' into 1317-add-sponsors-to-readmemd

    capricorn86 authored Mar 16, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    419300f View commit details
  8. Merge pull request #1320 from capricorn86/1317-add-sponsors-to-readmemd

    chore: [#1317] Improves documentation and adds sponsors to README.md
    capricorn86 authored Mar 16, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2d326c6 View commit details
  9. chore: [#1317] Improves documentation and adds sponsors to README.md

    capricorn86 committed Mar 16, 2024
    Copy the full SHA
    982d9bb View commit details
  10. Merge branch 'master' into 1317-add-sponsors-to-readmemd

    capricorn86 authored Mar 16, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a0eb44f View commit details
  11. Merge pull request #1321 from capricorn86/1317-add-sponsors-to-readmemd

    chore: [#1317] Improves documentation and adds sponsors to README.md
    capricorn86 authored Mar 16, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b64c9ac View commit details

Commits on Mar 17, 2024

  1. feat: [#1262] Adds support for AbortSignal.throwIfAborted()

    capricorn86 committed Mar 17, 2024
    Copy the full SHA
    efb3804 View commit details
  2. chore: [#1262] Fixes unit tests

    capricorn86 committed Mar 17, 2024
    Copy the full SHA
    e288c44 View commit details
  3. chore: [#1262] Fixes unit tests

    capricorn86 committed Mar 17, 2024
    Copy the full SHA
    63f8fe8 View commit details
  4. chore: [#1262] Fixes unit tests

    capricorn86 committed Mar 17, 2024
    Copy the full SHA
    13f0931 View commit details
  5. chore: [#1262] Fixes unit tests

    capricorn86 committed Mar 17, 2024
    Copy the full SHA
    97a3937 View commit details
  6. Merge pull request #1322 from capricorn86/1262-treewalker-with-nodefi…

    …ltershow_comment-is-not-working
    
    feat: [#1262] Adds support for AbortSignal.throwIfAborted()
    capricorn86 authored Mar 17, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9d6d1f3 View commit details
109 changes: 40 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,94 +1,65 @@
![Happy DOM Logo](https://github.com/capricorn86/happy-dom/raw/master/docs/happy-dom-logo.jpg)

# About
<h1 align="center">
<img alt="Happy DOM Logo" src="https://github.com/capricorn86/happy-dom/raw/master/docs/happy-dom-logo.jpg" />
</h1>
<p align="center">
A JavaScript implementation of a web browser without its graphical user interface.
</p>

[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/).
<p align="center">
<a href="https://www.npmjs.com/package/happy-dom">
<img alt="Published on NPM" src="https://img.shields.io/npm/v/happy-dom.svg">
</a>
</p>

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.
<p align="center">
<a href="https://github.com/capricorn86/happy-dom/wiki/">Documentation</a> | <a href="https://github.com/capricorn86/happy-dom/wiki/Getting-started">Getting started</a> | <a href="https://github.com/capricorn86/happy-dom/wiki/Setup-as-Test-Environment">Setup as Test Environment</a>
</p>

[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

### DOM Features
- Custom Elements (Web Components)

- Custom Elements (Web Components)
- Declarative Shadow DOM

- Shadow Root (Shadow DOM)
- Mutation Observer

- Declarative Shadow DOM
- Tree Walker

- Mutation Observer

- Tree Walker

- Fetch
- Fetch API

And much more..

### Works With

- [Google LitHTML](https://lit-html.polymer-project.org)

- [Google LitElement](https://lit-element.polymer-project.org)

- [React](https://reactjs.org)

- [Angular](https://angular.io/)

- [Vue](https://vuejs.org/)

### Module Systems

- [ESM](https://nodejs.org/api/esm.html#introduction)
- [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules)
## Works With

# Documentation
- [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/)

Read more about how to use Happy DOM in our [Wiki](https://github.com/capricorn86/happy-dom/wiki).
## Sponsors

# Packages
<p align="center"><b>Gold Sponsors</b></p>

This repository is a _Monorepo_. Each package lives under `packages/<package>`.
<p align="center"><a href="https://rtvision.com"><img alt="RTVision" width="100px" src="https://avatars.githubusercontent.com/u/8292810?s=200&v=4"></a></p>

### [![Published on npm](https://img.shields.io/npm/v/happy-dom.svg)](https://www.npmjs.com/package/happy-dom) [happy-dom](https://github.com/capricorn86/happy-dom/tree/master/packages/happy-dom)
<p align="center"><b>Sponsors</b></p>

This package contains the core functionality of Happy DOM.
<p align="center"><a href="https://sentry.io/"><img alt="Sentry" width="50px" src="https://avatars.githubusercontent.com/u/1396951?s=200&v=4"></a></p>

---
<p align="center"><b>Backers</b></p>

### [![Published on npm](https://img.shields.io/npm/v/@happy-dom/jest-environment.svg)](https://www.npmjs.com/package/@happy-dom/jest-environment) [jest-environment](https://github.com/capricorn86/happy-dom/tree/master/packages/jest-environment)
<p align="center"><a href="https://github.com/maxmilton"><img alt="Github user @maxmilton" src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/14946546?v=4&h=40&w=40&fit=cover&mask=circle&maxage=7d"></a> <a href="https://github.com/taufiq-dev"><img alt="Github user @taufiq-dev" src="https://images.weserv.nl/?url=avatars.githubusercontent.com/u/20721306?v=4&h=40&w=40&fit=cover&mask=circle&maxage=7d"></a></p>

This package makes it possible to use Happy DOM with [Jest](https://jestjs.io/).

---

### [![Published on npm](https://img.shields.io/npm/v/@happy-dom/global-registrator.svg)](https://www.npmjs.com/package/@happy-dom/global-registrator) [global-registrator](https://github.com/capricorn86/happy-dom/tree/master/packages/global-registrator)

A utility that registers Happy DOM globally, which makes it possible to use Happy DOM for testing in a Node environment.

# Performance

| Operation | JSDOM | Happy DOM |
| ------------------------------------ | ------- | --------- |
| Import / Require | 333 ms | 45 ms |
| Parse HTML | 256 ms | 26 ms |
| Serialize HTML | 65 ms | 8 ms |
| Render custom element | 214 ms | 19 ms |
| 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)

# Contributing
## Contributing

See [Contributing Guide](https://github.com/capricorn86/happy-dom/blob/master/docs/contributing.md).

# 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
## License

[<img alt="RTVision" width="120px" src="https://avatars.githubusercontent.com/u/8292810?s=200&v=4" />](https://rtvision.com)
MIT License © 2020-Present [David Ortner](https://github.com/capricorn86)
79 changes: 7 additions & 72 deletions packages/global-registrator/README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,16 @@
![Happy DOM Logo](https://github.com/capricorn86/happy-dom/raw/master/docs/happy-dom-logo.jpg)

# About
This package makes it possible to register [Happy DOM](https://github.com/capricorn86/happy-dom) in the global scope, e.g. for testing purposes.

[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/).

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).

This package contains a utility that registers [Happy DOM](https://github.com/capricorn86/happy-dom) globally, which makes it possible to use [Happy DOM](https://github.com/capricorn86/happy-dom) for testing in a Node environment.

### DOM Features

- Custom Elements (Web Components)

- Shadow Root (Shadow DOM)

- Declarative Shadow DOM

- Mutation Observer

- Tree Walker

- Fetch

And much more..

### Works With

- [Google LitHTML](https://lit-html.polymer-project.org)

- [Google LitElement](https://lit-element.polymer-project.org)

- [React](https://reactjs.org)

- [Angular](https://angular.io/)

- [Vue](https://vuejs.org/)

### Module Systems

- [ESM](https://nodejs.org/api/esm.html#introduction)
- [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules)

# Installation
## Installation

```bash
npm install @happy-dom/global-registrator --save-dev
```

# Usage
## Usage

## Register
#### Register

```javascript
import { GlobalRegistrator } from '@happy-dom/global-registrator';
@@ -66,7 +25,7 @@ const button = document.querySelector('button');
console.log(button.innerText);
```

## Unregister
#### Unregister

```javascript
import { GlobalRegistrator } from '@happy-dom/global-registrator';
@@ -79,30 +38,6 @@ GlobalRegistrator.unregister();
console.log(global.document);
```

# Documentation

Read more about how Happy DOM works in our [documentation](https://github.com/capricorn86/happy-dom/wiki).

# Performance

| Operation | JSDOM | Happy DOM |
| ------------------------------------ | ------- | --------- |
| Import / Require | 333 ms | 45 ms |
| Parse HTML | 256 ms | 26 ms |
| Serialize HTML | 65 ms | 8 ms |
| Render custom element | 214 ms | 19 ms |
| 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)

# 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
## Happy DOM

[<img alt="RTVision" width="120px" src="https://avatars.githubusercontent.com/u/8292810?s=200&v=4" />](https://rtvision.com)
[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/)
118 changes: 11 additions & 107 deletions packages/happy-dom/README.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,34 @@
![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/).

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
## DOM Features

- Custom Elements (Web Components)

- Shadow Root (Shadow DOM)

- Declarative Shadow DOM

- Mutation Observer

- Tree Walker

- Fetch
- Fetch API

And much more..

### Works With

- [Google LitHTML](https://lit-html.polymer-project.org)

- [Google LitElement](https://lit-element.polymer-project.org)

- [React](https://reactjs.org)

- [Angular](https://angular.io/)

- [Vue](https://vuejs.org/)

### Module Systems

- [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>';
## Documentation

const container = document.querySelector('.container');
const button = document.createElement('button');
[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/)

container.appendChild(button);
## Works With

// Outputs "<div class="container"><button></button></div>"
console.log(document.body.innerHTML);
[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/)

// Closes the window
await window.happyDOM.close();
```
## Module Systems

## Browser
[ESM](https://nodejs.org/api/esm.html#introduction) | [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules)

```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
## Performance

| Operation | JSDOM | Happy DOM |
| ------------------------------------ | ------- | --------- |
@@ -110,29 +37,6 @@ Read more about how to use Happy DOM in our [Wiki](https://github.com/capricorn8
| Serialize HTML | 65 ms | 8 ms |
| Render custom element | 214 ms | 19 ms |
| 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)
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ export default class BrowserFrameNavigator {
let responseText: string;

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