简体   繁体   English

在浏览器中调试 HTML5 服务器发送的事件

[英]Debugging HTML5 Server-Sent Events in-browser

Is there any way of viewing/debugging Server-Sent Events in Chrome (or perhaps Firefox)?有没有办法在 Chrome(或者 Firefox)中查看/调试服务器发送的事件 I was hoping they'd appear in the Network tab of Chrome's developer tools.我希望它们会出现在 Chrome 开发人员工具的网络选项卡中。 The closest way I know of is to drop down to Wireshark, but this is fairly cumbersome in comparison.我所知道的最接近的方法是使用 Wireshark,但相比之下,这相当麻烦。

For example, go to http://www.emojitracker.com/ .例如,转到http://www.emojitracker.com/ You'll see the page updating in real time with data from the server, but no activity appears in the network tab.您会看到页面随着来自服务器的数据实时更新,但网络选项卡中没有显示任何活动。 (It subscribes to server events on line 97 of /application.js.) (它在 /application.js 的第 97 行订阅服务器事件。)

The events appear now in Network Tab.事件现在出现在网络选项卡中。 Click on the URL of the SSE stream and you will have an "EventStream" tab:单击 SSE 流的 URL,您将有一个“EventStream”选项卡:

在此处输入图片说明

Visit chrome://cache and click on the URL of the server-sent event.访问chrome://cache并单击服务器发送事件的 URL。 Then you will be redirected to a page like chrome://view-http-cache/http://emojitrack-gostreamer.herokuapp.com/subscribe/eps which contains the following:然后你将被重定向到一个页面,如chrome://view-http-cache/http://emojitrack-gostreamer.herokuapp.com/subscribe/eps ,其中包含以下内容:

http://emojitrack-gostreamer.herokuapp.com/subscribe/eps
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Content-Type: text/event-stream; charset=utf-8
Server: emojitrack-gostreamer
Date: Sun, 21 Sep 2014 11:17:48 GMT
Via: 1.1 vegur
00000000: fc 00 00 00 03 00 04 00 fd 79 7d c4 27 62 2e 00  .........y}.'b..
00000010: 0c 87 7f c4 27 62 2e 00 c8 00 00 00 48 54 54 50  ....'b......HTTP
00000020: 2f 31 2e 31 20 32 30 30 20 4f 4b 00 41 63 63 65  /1.1 200 OK.Acce
00000030: 73 73 2d 43 6f 6e 74 72 6f 6c 2d 41 6c 6c 6f 77  ss-Control-Allow
00000040: 2d 4f 72 69 67 69 6e 3a 20 2a 00 43 61 63 68 65  -Origin: *.Cache
00000050: 2d 43 6f 6e 74 72 6f 6c 3a 20 6e 6f 2d 63 61 63  -Control: no-cac
00000060: 68 65 00 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a  he.Content-Type:
00000070: 20 74 65 78 74 2f 65 76 65 6e 74 2d 73 74 72 65   text/event-stre
00000080: 61 6d 3b 20 63 68 61 72 73 65 74 3d 75 74 66 2d  am; charset=utf-
00000090: 38 00 53 65 72 76 65 72 3a 20 65 6d 6f 6a 69 74  8.Server: emojit
000000a0: 72 61 63 6b 2d 67 6f 73 74 72 65 61 6d 65 72 00  rack-gostreamer.
000000b0: 44 61 74 65 3a 20 53 75 6e 2c 20 32 31 20 53 65  Date: Sun, 21 Se
000000c0: 70 20 32 30 31 34 20 31 31 3a 31 37 3a 34 38 20  p 2014 11:17:48 
000000d0: 47 4d 54 00 56 69 61 3a 20 31 2e 31 20 76 65 67  GMT.Via: 1.1 veg
000000e0: 75 72 00 00 0d 00 00 00 35 30 2e 31 37 2e 32 34  ur......50.17.24
000000f0: 35 2e 32 31 33 00 00 00 50 00 00 00 01 00 00 00  5.213...P.......

00000000: 64 61 74 61 3a 7b 22 31 46 34 34 45 22 3a 31 2c  data:{"1F44E":1,
00000010: 22 31 46 34 36 44 22 3a 31 7d 0a 0a 64 61 74 61  "1F46D":1}..data
00000020: 3a 7b 22 31 46 34 41 39 22 3a 31 2c 22 31 46 36  :{"1F4A9":1,"1F6
00000030: 31 32 22 3a 31 7d 0a 0a 64 61 74 61 3a 7b 22 31  12":1}..data:{"1
00000040: 46 34 39 36 22 3a 31 7d 0a 0a 64 61 74 61 3a 7b  F496":1}..data:{
00000050: 22 31 46 36 31 44 22 3a 31 7d 0a 0a 64 61 74 61  "1F61D":1}..data
00000060: 3a 7b 22 31 46 33 35 35 22 3a 31 2c 22 31 46 36  :{"1F355":1,"1F6
00000070: 31 44 22 3a 31 2c 22 31 46 36 33 34 22 3a 31 7d  1D":1,"1F634":1}
00000080: 0a 0a 64 61 74 61 3a 7b 22 31 46 33 33 39 22 3a  ..data:{"1F339":

Press F5 to refresh the view.按 F5 刷新视图。 (If the requesting tab is closed the item is evicted from the cache and you'll see " no matching cache entry for: http://emojitrack-gostreamer.herokuapp.com/subscribe/eps "). (如果请求选项卡关闭,该项目将从缓存中逐出,您将看到“ no matching cache entry for: http://emojitrack-gostreamer.herokuapp.com/subscribe/eps ”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM