diff --git a/CHANGELOG.md b/CHANGELOG.md index 91709175..be45c61f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/src/broadcast-channel.js b/src/broadcast-channel.js index 4c8ecb19..d9114829 100644 --- a/src/broadcast-channel.js +++ b/src/broadcast-channel.js @@ -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);