【问题标题】:Rocket Chat, Failed to execute 'postMessage' on 'DOMWindow'Rocket Chat,无法在“DOMWindow”上执行“postMessage”
【发布时间】:2019-11-05 09:07:28
【问题描述】:

在我的网络应用程序中,我使用iframe 加载“RocketChat”聊天实例。但是当我尝试使用window.postMessage() 登录火箭聊天时,浏览器给了我一个控制台错误。请找到下面的屏幕截图。

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://haulmatic.rocket.chat') does not match the recipient window's origin ('http://localhost:3030').

axios.post('https://myDomain.rocket.chat/api/v1/login', {
            username: '<myUserName>',
            password: '<myPassword>'
        }).then(function (response) {
            if (response.data.status === 'success') {
                res.set('Content-Type', 'text/html');
                res.send(`
                <iframe id="iframe" width="400px" height="900px" src="https://myDomain.rocket.chat?origin=http://localhost:3030"></iframe>
                <script>
                    window.parent.postMessage({
                        event: 'login-with-token',
                        loginToken: '${ response.data.data.authToken }'
                    }, 'https://myDomain.rocket.chat/'); // rocket.chat's URL   206.189.138.6:3000
                </script> 
                `);
            }
        }).catch(function() {
            res.sendStatus(401);
        });

Reference : rocket chat iframe authentication documentation

【问题讨论】:

    标签: authentication iframe browser cross-domain rocket.chat


    【解决方案1】:

    您需要使用有效的用户令牌向 iframe 发送命令,该用户令牌已经是您在 iframe 中浏览的频道的成员。

    这是我的详细回答: https://stackoverflow.com/a/58820488/628592

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 2018-05-30
      • 2018-11-24
      • 2019-12-09
      • 2016-12-11
      • 1970-01-01
      • 2016-08-20
      • 2015-02-18
      相关资源
      最近更新 更多