Javascript - Reading binary data when using chrome.devtools.network.onRequestFinished

人走茶凉 提交于 2019-12-22 18:50:12

问题


So I am building a Chrome DevTools extension that inspects binary traffic on particular website.

Requests on site are made with responseType = "blob".

Now when I get request with chrome.devtools.network.onRequestFinished and then access its content with request.getContent(), I get string as response and not blob.

This string looks like some kind of binary string but not sure how it is encoded. I tried transforming it to base64 string with a lot of different transforms (Utf-8 to latin, Utf-16 to latin, ... ) but nothing gave correct result.

Any idea how to get correct result?

Update:

This is comparison of results (as Uint8Array) from client and extension.

Client:
[170, 69, 224, 171, 51, 233, 216, 82, 197, 35, 170, 213, 145, 197, 218, 82, 72, 85, 33, 77, 81, 88, 93, 16, 97, 234, 253, 208, 203, 221, 44, 44]

Extension:
[65533, 69, 65533, 65533, 51, 65533, 65533, 82, 65533, 35, 65533, 81, 65533, 65533, 82, 72, 85, 33, 77, 81, 88, 93, 16, 97, 65533, 65533, 65533, 65533, 65533, 44, 44]

Notice how every byte that is over 128 is converted to 65533 byte (Replacement character) in extension?

Now how can I access pure binary data?


回答1:


const data = Uint8Array.from(atob(content), c => c.charCodeAt(0)) ;


来源:https://stackoverflow.com/questions/32481473/javascript-reading-binary-data-when-using-chrome-devtools-network-onrequestfin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!