MCPcopy
hub / github.com/mswjs/msw / postMessage

Method postMessage

src/browser/utils/workerChannel.ts:162–171  ·  view source on GitHub ↗

* Send data to the Service Worker controlling this client. * This triggers the `message` event listener on ServiceWorkerGlobalScope.

(type: OutgoingWorkerEvents)

Source from the content-addressed store, hash-verified

160 * This triggers the `message` event listener on ServiceWorkerGlobalScope.
161 */
162 public postMessage(type: OutgoingWorkerEvents): void {
163 invariant(
164 SUPPORTS_SERVICE_WORKER,
165 'Failed to post message on a WorkerChannel: the Service Worker API is unavailable in this environment. This is likely an issue with MSW. Please report it on GitHub: https://github.com/mswjs/msw/issues',
166 )
167
168 this.#getWorker().then((worker) => {
169 worker.postMessage(type)
170 })
171 }
172
173 /**
174 * Terminal teardown. Removes the `navigator.serviceWorker` message listener

Callers

nothing calls this directly

Calls 2

invariantFunction · 0.85
postMessageMethod · 0.45

Tested by

no test coverage detected