【问题标题】:Event Stream data not showing in Chrome console事件流数据未显示在 Chrome 控制台中
【发布时间】:2019-08-07 15:23:25
【问题描述】:

我的前端有一个 EventSource 侦听器,它调用了一个复杂的后端方案。此代码块是用 Typescript 编写的。

import * as EventSource from 'eventsource';      

private streamData() {
    let source = new EventSource('http://localhost:3000/websocket/server/stream');

    source.onopen = (e) => {

    };

    source.onmessage = (e) => {
      console.log('id: ' + (<any>e).lastEventId + '; type: ' + e.type + ' data: ' + e.data);
    };
  }

然后我将以下响应发送回我的服务器:

res.write('id: ' + this.messageId++ + '\n');
res.write('type: message\n');
res.write('data: ' + message + '\n\n');
res.flush();

现在,在 Chrome 控制台上,我获得了所有需要的数据。

但是,在 xhr 监视器上,我看不到 EventStream 数据。

我在前端获取信息,所以这对我来说不是阻塞问题,但可能会在稍后的调试中造成一些问题。

【问题讨论】:

  • 在浏览器的WS选项卡里,看不到流吗?
  • 不,它是空的。我只能在 XHR 选项卡上看到流。
  • 很遗憾,我无法为您提供帮助,因为我似乎无法解决这个问题,但这是一个新用户提出的写得很好且令人耳目一新的问题,恭喜
  • 你找到这个问题的答案了吗?我有完全相同的问题。
  • 你使用npmjs.com/package/eventsource 吗?我有同样的问题

标签: javascript typescript http google-chrome-devtools event-stream


【解决方案1】:

我有同样的问题。仅当您使用 EventSource 类的内置浏览器实现时,才在使用 eventsource polyfill 时显示数据。

【讨论】:

  • 这实际上是正确的,当我切换到政治 chrome 时停止显示消息
猜你喜欢
  • 2022-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-15
  • 2017-01-11
相关资源
最近更新 更多