Skip to content

Commit 4c63b21

Browse files
kovanclaude
andcommitted
doc: fix URL postMessage example in worker_threads
The example claimed that posting a URL object via MessageChannel would print an empty object, but since v21.0.0 (commit d920b7c) it throws a DataCloneError. Update the example and surrounding text to reflect the current behavior. Fixes: #60504 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3bbed16 commit 4c63b21

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

doc/api/worker_threads.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,17 +1416,14 @@ port2.postMessage(new Foo());
14161416
// Prints: { c: 3 }
14171417
```
14181418
1419-
This limitation extends to many built-in objects, such as the global `URL`
1420-
object:
1419+
Some built-in objects cannot be cloned at all. For example, posting a
1420+
`URL` object throws a `DataCloneError`:
14211421
14221422
```js
14231423
const { port1, port2 } = new MessageChannel();
14241424

1425-
port1.onmessage = ({ data }) => console.log(data);
1426-
14271425
port2.postMessage(new URL('https://example.org'));
1428-
1429-
// Prints: { }
1426+
// Throws DataCloneError: Cannot clone object of unsupported type.
14301427
```
14311428
14321429
### `port.hasRef()`

0 commit comments

Comments
 (0)