我需要在指向同一站点的同一浏览器的 2 个选项卡之间共享一些信息。我正在使用 BroadcastChannel.onmessage 事件处理程序,详情如下: https ://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel/onmessage
在我定义的发件人选项卡javascript代码中:
var bc = new BroadcastChannel('my_bc_channel');
bc.postMessage(i); //where i is simply the line number i want to share
在接收选项卡中:
var bc = new BroadcastChannel('my_bc_channel');
//then use this to receive the incoming messages:
bc.onmessage = function (ev) {
last_line = ev.data
}
我的代码在 Chrome 中运行良好,但在 Firefox 中没有任何作用(Windows 下新安装的最新版本 70)。我在上面给出的链接中的兼容性图表表明它应该在 Firefox 版本 38 上运行。
问题是,我不确定如何调试它。我在控制台中没有任何错误消息。我不知道是不是发件人代码没有发送任何东西。但显然接收代码没有被触发,所以我猜 .onmessage 事件没有被检测到。如果发送了消息,我在哪里可以看到 javascript 控制台?