Skip to content

Commit

Permalink
Fix postMessage({}, '*') causes slackin to throw
Browse files Browse the repository at this point in the history
Non-slackin code may postMessage() to the same window (in my case, a
Twitter button), and unlike slackin, may choose to send an object as a
message rather than a string. Unlike strings, not all objects have a
.substr() method, so slackin doing e.data.substr() throws an exception:
https://git.io/v2N5t
  • Loading branch information
laughinghan committed Mar 6, 2016
1 parent 00aec7e commit 918b2b2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/assets/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
var id = Math.random() * (1 << 24) | 0;
iframe.contentWindow.postMessage('slackin:' + id, '*');
window.addEventListener('message', function(e){
if (typeof e.data !== 'string') return;

// show dialog upon click
if ('slackin-click:' + id == e.data) {
showDialog(iframe);
Expand Down

0 comments on commit 918b2b2

Please sign in to comment.