广播频道 API 通信在 servicenow 中不起作用,iframe 和子窗口从 chrome 浏览器中具有相同来源的 iframe 打开

Broadcast Channel API communication is not working inside servicenow iframe and child window opened from iframe with same origin in chrome browser

提问人:Rajkumar B 提问时间:10/14/2023 最后编辑:Rajkumar B 更新时间:10/23/2023 访问量:143

问:

我们创建了一个包含 2 页broadcast.html和receiver.html的 Web 应用程序。Broadcast.html使用 OpenFrame Widget 在 ServiceNow CRM 中添加为 iframe,receiver.html 与 broadcast.html 分开打开。我们尝试使用广播 api 在 2 个页面之间进行通信,并且在 servicenow 中打开时它在 chrome 浏览器中不起作用,但如果 servicenow 中没有加载broadcast.html则通信正常工作。

代码附在下面

Openframe 小部件代码

<html> 
<body style="padding-top: 0rem;">
<iframe id="softphone" style="width: 100%; height: 100%; position: fixed; border: none;" allow="microphone *" src="https://localhost:9981/broadcast.html" />
</body>
</html>

广播 HTML

<!DOCTYPE html>

<body>
  <!-- The title will change to greet the user -->
  <h1 id="title">Hey</h1>
  <input id="name-field" placeholder="Enter Your Name"/>
  
</body>
<script>
    window.onload=function(){
        window.open("/reciever.html?ts=" + new Date().getTime(), "reciever", "fullscreen=no, width=455, height=320, resizable=no, location=no'");
        //window.open("reciever.html");
    }

var bc = new BroadcastChannel('test_channel');

(()=>{
  const title = document.getElementById('title');
  const nameField = document.getElementById('name-field');
  const setTitle = (userName) => {
    title.innerHTML = 'Hey ' + userName;
  }

  

  // When the page loads check if the title is in our localStorage
  if (localStorage.getItem('title')) {
    setTitle(localStorage.getItem('title'));
  } else {
    setTitle('please tell us your name');
  }

  nameField.onchange = (e) => {
    const inputValue = e.target.value;
    // In the localStorage we set title to the user's input
    localStorage.setItem('title', inputValue);
    // Update the title on the current page 
    setTitle(inputValue);
    // Tell the other pages to update the title
    bc.postMessage(inputValue);
  }
})()
</script>
</html>

接收器 HTML

<!DOCTYPE html>

<body>
  <!-- The title will change to greet the user -->
  <h1 id="title">Hey</h1>

  </body>
  <script>
    var bc = new BroadcastChannel('test_channel');

    bc.onmessage = (messageEvent) => {
        console.log(messageEvent.data);
        document.getElementById('title').innerHTML=messageEvent.data;
  
  }
  </script>
  </html>
Google-Chrome iframe CRM Service现在 广播频道

评论

0赞 tnurmi 10/19/2023
我们完全有另一个产品,但我们现在突然观察到同样的问题。似乎只发生在 Chrome 上。在我们的测试中,它可以很好地与 Edge 和 Firefox 配合使用。在 Chrome 中,BroadcastChannel 似乎只是默默地无法传递消息。没有警告,错误,我们使用常规开发人员工具栏无法观察到任何东西。但奇怪的是,这并不是所有用户都会发生的。Chrome 上的某些用户没有遇到此问题。我们正在尝试收集正常/无效的 Chrome 版本详细信息。
0赞 tnurmi 10/19/2023
建议:从标题中删除“servicenow”

答: 暂无答案