I do not recommend to provide it directly, because there are too many tool libraries for encapsulating postMessage/onMessage, the most typical one is ChromeLab’s comlink, ref: GitHub - GoogleChromeLabs/comlink: Comlink makes WebWorkers enjoyable.