本文介绍了Javascript - 使用chrome.devtools.network.onRequestFinished时读取二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在构建一个Chrome DevTools扩展程序,用于检查特定网站上的二进制流量。

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

网站上的请求是使用 responseType =blob

现在,当我收到 chrome.devtools.network.onRequestFinished 的请求,然后使用 request.getContent()访问其内容,我得到字符串作为回复,而不是 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.

此字符串看起来像某种二进制字符串,但不确定它是如何编码的。我尝试将它转换为 base64 string ,有很多不同的转换(Utf-8到拉丁语,Utf-16到latin,......)但没有给出正确的结果。

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?

更新:

这是客户和分机的结果比较(如 Uint8Array )。

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

客户:

[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]

扩展:

[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]

请注意,超过128的每个字节如何在扩展名中转换为65533字节(替换字符)?

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?

推荐答案

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

这篇关于Javascript - 使用chrome.devtools.network.onRequestFinished时读取二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:04