MCPcopy
hub / github.com/ampproject/worker-dom

github.com/ampproject/worker-dom @v0.36.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.36.0 ↗
1,261 symbols 3,598 edges 338 files 221 documented · 18%
README

WorkerDOM

An in-progress implementation of the DOM API intended to run within a Web Worker.

Purpose: Move complexity of intermediate work related to DOM mutations to a background thread, sending only the necessary manipulations to a foreground thread.

Use Cases: 1. Embedded content from a third party living side by side with first party code. 2. Mitigation of expensive rendering for content not requiring synchronous updates to user actions. 3. Retaining main thread availablity for high priority updates by async updating elsewhere in a document.

For more information, visit our blog post announcing WorkerDOM or checkout the slides from the announcement at JSConf US.

Installation

npm install @ampproject/worker-dom

Usage

WorkerDOM comes in two flavours, a global variant and a module variant. It is possible to include the WorkerDOM main thread code within your document directly or via a bundler. Here's how you might do so directly:

<script src="https://github.com/ampproject/worker-dom/raw/v0.36.0/path/to/workerdom/dist/main.mjs" type="module"></script>
<script src="https://github.com/ampproject/worker-dom/raw/v0.36.0/path/to/workerdom/dist/main.js" nomodule defer></script>

WorkerDOM allows us to upgrade a specific section of the document to be driven by a worker. For example, imagine a div node in the page like so:






To upgrade this node using the module version of the code, we can directly import upgradeElement and use it like this:

<script type="module">
  import {upgradeElement} from './dist/main.mjs';
  upgradeElement(document.getElementById('upgrade-me'), './dist/worker/worker.mjs');
</script>

The nomodule format exposes the global MainThread, and could upgrade the div in the following way:

<script nomodule async=false defer>
  document.addEventListener('DOMContentLoaded', function() {
    MainThread.upgradeElement(document.getElementById('upgrade-me'), './dist/worker/worker.js');
  }, false);
</script>

AMP Distribution for amp-script

WorkerDOM has a special output variant that supplies additional hooks for safety features e.g. HTML sanitization. This variant is distributed under the amp folder for main and worker thread binaries:

amp/main.mjs
amp/worker/worker.mjs

This output assumes the consumer will compile this distributed JavaScript to ensure it works with older user-agents.

Debug Distribution

WorkerDOM also has an output variant that includes additional debugging messages. This variant is distributed in the debug folder.

debug/main.mjs
debug/main.js
debug/worker/worker.mjs
debug/worker/worker.js

Running Demos Locally

After cloning the repository, you can try out the debug demos with the following.

npm run demo

This script will build the current version of WorkerDOM and start up a local webserver.

Which JavaScript APIs can I use?

Currently, most DOM elements and their properties are supported. DOM query APIs like querySelector have partial support. Browser APIs like History are not implemented yet. Please see the API support matrix here.

Which Browsers are supported?

In general we support the latest two versions of major browsers like Chrome, Firefox, Edge, Safari, Opera and UC Browser. We support desktop, phone, tablet and the web view version of these respective browsers.

Beyond that, we aim for very wide browser support and we accept fixes for all browsers with market share greater than 1 percent.

In particular, we try to maintain "it might not be perfect but isn't broken"-support for IE 11, iOS 8, the Android 4.0 system browser and Chrome 41.

Local Development

Local development of WorkerDOM assumes the following: 1. Familiarity with npm or yarn 2. Latest LTS release of Node (10 at time of writing) available. 3. Comfort with TypeScript, the codebase and tests are entirely written in TypeScript.

Release Log

Each release includes a log of changes with the newly released version. You can find the log here: https://github.com/ampproject/worker-dom/releases

Security disclosures

The AMP Project accepts responsible security disclosures through the Google Application Security program.

Code of conduct

The AMP Project strives for a positive and growing project community that provides a safe environment for everyone. All members, committers and volunteers in the community are required to act according to the code of conduct.

License

worker-dom is licensed under the Apache License, Version 2.0.

Extension points exported contracts — how you extend this code

TransferrableObject (Interface)
(no doc) [7 implementers]
src/worker-thread/worker-thread.d.ts
OffscreenCanvas (Interface)
(no doc) [3 implementers]
src/test/DocumentCreation.ts
TransferrableTouch (Interface)
(no doc)
src/transfer/TransferrableEvent.ts
DeserializedArgs (Interface)
(no doc)
src/main-thread/deserializeTransferrableObject.ts
Elements (Interface)
(no doc)
src/third_party/html-parser/html-parser.ts
CanvasPattern (Interface)
(no doc) [4 implementers]
src/worker-thread/canvas/CanvasTypes.d.ts
Emitter (Interface)
(no doc)
src/test/Emitter.ts
TransferrableTouchList (Interface)
(no doc)
src/transfer/TransferrableEvent.ts

Core symbols most depended-on inside this repo

createElement
called by 432
src/worker-thread/dom/Document.ts
createTestingDocument
called by 154
src/test/DocumentCreation.ts
setAttribute
called by 150
src/main-thread/main-thread.d.ts
n
called by 144
demo/vue-todomvc/app.js
toLower
called by 109
src/utils.ts
getAttribute
called by 77
src/worker-thread/dom/Element.ts
t
called by 60
demo/vue-todomvc/app.js
createTextNode
called by 58
src/worker-thread/dom/Document.ts

Shape

Function 656
Method 370
Class 133
Interface 69
Enum 33

Languages

TypeScript100%

Modules by API surface

demo/vue-todomvc/app.js247 symbols
src/worker-thread/canvas/CanvasRenderingContext2D.ts71 symbols
src/worker-thread/canvas/OffscreenCanvasPolyfill.ts70 symbols
src/worker-thread/canvas/CanvasTypes.d.ts52 symbols
demo/preact-dbmon/dbmon.js47 symbols
demo/preact-todomvc/app.js41 symbols
src/worker-thread/dom/Element.ts34 symbols
src/worker-thread/dom/Node.ts22 symbols
src/worker-thread/dom/DOMTokenList.ts15 symbols
src/worker-thread/Event.ts15 symbols
src/transfer/TransferrableMutation.ts15 symbols
src/test/main-thread/helpers/env.ts15 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@ampproject/filesize4.3.0 · 1×
@ampproject/rollup-plugin-closure-compiler0.27.0 · 1×
@babel/cli7.27.2 · 1×
@babel/core7.27.4 · 1×
@babel/helper-plugin-utils7.0.0 · 1×
@babel/plugin-transform-react-jsx7.24.6 · 1×
@babel/preset-env7.27.2 · 1×
@rollup/plugin-babel6.0.4 · 1×
@rollup/plugin-replace6.0.2 · 1×
@rollup/plugin-terser0.4.4 · 1×
@types/node18.19.112 · 1×
@types/sinon10.0.20 · 1×

For agents

$ claude mcp add worker-dom \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact