火箭聊天,无法在'DOMWindow'上执行'postMessage'

问题描述 投票:0回答:1

在我的Web应用程序中,我使用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个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.