This example shows how to use an OffscreenCanvasContext with a web worker.
View this demo live.
To run this code locally you'll need to serve it. If you have node installed, navigate to the folder containing the code and run lite-server:
cd web-workers/offscreen-canvas-worker
npx lite-server