From 1a3c56d00122f73b0c3d2b3b4f6d0d8d6c4752d6 Mon Sep 17 00:00:00 2001 From: pubkey <8926560+pubkey@users.noreply.github.com> Date: Thu, 3 Feb 2022 14:47:11 +0100 Subject: [PATCH] IMPROVE error message when calling `postMessage` to a closed channel --- CHANGELOG.md | 5 +++++ src/broadcast-channel.js | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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);