Skip to content

Commit 1a3c56d

Browse files
committed
IMPROVE error message when calling postMessage to a closed channel
1 parent e489c14 commit 1a3c56d

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
4+
## X.X.X (comming soon)
5+
6+
- Improve error message when calling `postMessage` to a closed channel.
7+
38
## 4.9.0 (23 December 2021)
49

510
Bugfixes:

src/broadcast-channel.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ BroadcastChannel.prototype = {
112112
if (this.closed) {
113113
throw new Error(
114114
'BroadcastChannel.postMessage(): ' +
115-
'Cannot post message after channel has closed'
115+
'Cannot post message after channel has closed ' +
116+
/**
117+
* In the past when this error appeared, it was realy hard to debug.
118+
* So now we log the msg together with the error so it at least
119+
* gives some clue about where in your application this happens.
120+
*/
121+
JSON.stringify(msg)
116122
);
117123
}
118124
return _post(this, 'message', msg);

0 commit comments

Comments
 (0)