Chrome浏览器控制台中未显示事件流数据

时间:2019-03-16 20:50:30

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

我的前端有一个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控制台上,我获得了所有需要的数据。 enter image description here

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

enter image description here

我在前端获得了信息,所以这对我来说不是一个阻碍性的问题,但是在以后的调试中可能会带来一些问题。

1 个答案:

答案 0 :(得分:0)

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

相关问题