diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-02 10:08:49 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-02 10:08:49 +0900 |
commit | 044f24efb64ec52dfdb02e0e0807bc4545c4a21c (patch) | |
tree | 1cb621bd8ea538e128a7263012d3c8bc077e2e0d /src/shared/messages.js | |
parent | f1b9c6ba9d33fe1927c4855d4981d88ad73d5818 (diff) | |
parent | 02ea10a357955752dda4c72c49de2340997c9818 (diff) |
Merge branch 'error-line'
Diffstat (limited to 'src/shared/messages.js')
-rw-r--r-- | src/shared/messages.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/shared/messages.js b/src/shared/messages.js new file mode 100644 index 0000000..517fc4c --- /dev/null +++ b/src/shared/messages.js @@ -0,0 +1,19 @@ +const receive = (win, callback) => { + win.addEventListener('message', (e) => { + let message; + try { + message = JSON.parse(e.data); + } catch (e) { + // ignore message posted by author of web page + return; + } + + callback(message); + }) +} + +const send = (win, message) => { + win.postMessage(JSON.stringify(message), '*'); +} + +export { receive, send }; |