Skip to content

stan-kondrat/worker-dom-access

Repository files navigation

Access DOM in Web Worker

index.js

// Create Web Worker
const worker = new Worker('worker.js');

// Create proxy
const targetProxy = new TargetProxy(worker);

// Gave access to window object
targetProxy.register('window', window);

worker.js

// link proxy object
const window: any = WorkerProxyObject('window');

// eval native alert function in GUI thread from worker thread
window.alert('Hello From Worker');

// direct access to DOM from worker
window.document.body.innerText = 'Hello From Worker';

How it works

In two words Proxy & Promise. For more details, please see worker.ts file (less than 100 lines of code).

Fell free to conribute

About

Access DOM in Web Worker ⚠️ Proof-of-Concept

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published