问题
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