Skip to content

Commit 7da2a44

Browse files
kovanclaude
authored 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> Signed-off-by: Kit Dallege <xaum.io@gmail.com> PR-URL: #62203 Fixes: #60504 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 2e4a0d0 commit 7da2a44

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

doc/api/worker_threads.md

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

1421-
port1.onmessage = ({ data }) => console.log(data);
1422-
14231421
port2.postMessage(new URL('https://example.org'));
1424-
1425-
// Prints: { }
1422+
// Throws DataCloneError: Cannot clone object of unsupported type.
14261423
```
14271424
14281425
### `port.hasRef()`

0 commit comments

Comments
 (0)