Skip to content

Commit

Permalink
IMPROVE error message when calling postMessage to a closed channel
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Feb 3, 2022
1 parent e489c14 commit 1a3c56d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG


## X.X.X (comming soon)

- Improve error message when calling `postMessage` to a closed channel.

## 4.9.0 (23 December 2021)

Bugfixes:
Expand Down
8 changes: 7 additions & 1 deletion src/broadcast-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ BroadcastChannel.prototype = {
if (this.closed) {
throw new Error(
'BroadcastChannel.postMessage(): ' +
'Cannot post message after channel has closed'
'Cannot post message after channel has closed ' +
/**
* In the past when this error appeared, it was realy hard to debug.
* So now we log the msg together with the error so it at least
* gives some clue about where in your application this happens.
*/
JSON.stringify(msg)
);
}
return _post(this, 'message', msg);
Expand Down

0 comments on commit 1a3c56d

Please sign in to comment.