Title: Cross-process communication
Published: July 15, 2026
Last modified: July 16, 2026

---

# Cross-process communication

[ Back to top](https://developer.wordpress.org/playground/developers/architecture/browser-cross-process-communication/?output_format=md#wp--skip-link--target)

`@php-wasm/web` uses the [Comlink](https://github.com/GoogleChromeLabs/comlink) 
library to turns the one-way `postMessage` available in JavaScript into a two-way
communication channel.

If `postMessage` sounds unfamiliar, it’s what JavaScript threads use to communicate.
Please review the [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)
before continuing.

By default, `postMessage` does not offer any request/response mechanics. You may
send messages to another thread and you may independently receive messages from 
it, but you can’t send a message and await a response to that specific message.

To quote the [Comlink](https://github.com/GoogleChromeLabs/comlink) library documentation:

**main.js**

    ```javascript
    async function init() {
        const worker = new Worker('worker.js');
        // WebWorkers use `postMessage` and therefore work with Comlink.
        const obj = Comlink.wrap(worker);
        alert(`Counter: ${await obj.counter}`);
        await obj.inc();
        alert(`Counter: ${await obj.counter}`);
    }
    init();
    ```

**worker.js**

    ```javascript
    importScripts('https://unpkg.com/comlink/dist/umd/comlink.js');

    const obj = {
        counter: 0,
        inc() {
            this.counter++;
        },
    };

    Comlink.expose(obj);
    ```

First published

July 15, 2026

Last updated

July 16, 2026

Edit article

[ Improve it on GitHub: Cross-process communication ](https://raw.githubusercontent.com/WordPress/wordpress-playground/trunk/packages/docs/site/docs/developers/23-architecture/14-browser-cross-process-communication.md)

Changelog

[ See list of changes: Cross-process communication ](https://developer.wordpress.org/playground/developers/architecture/browser-cross-process-communication/?output_format=md#)

[  Previous: Scopes](https://developer.wordpress.org/playground/developers/architecture/browser-scopes/)

[  Next: WordPress support](https://developer.wordpress.org/playground/developers/architecture/wordpress/)