Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
With binary data becoming more and more common in the browser, thanks to ArrayBuffers and TypedArrays and all the specifications that use them, we need to be able to properly log these data types to the console.
On the surface this is possible with
Lets assume we some binary data (ESC/POS commands for a receipt printer) in the form of a
We then log the
Then we get the following in the console
For other TypedArrays this should also work and reveal the byte order of the individual elements in the array:
This is even useful for looking at the UTF-8 encoding of strings:
I've created a 'one-liner' polyfill that does exactly this and can be found here:
The specification purposefully doesn't describe what log lines should look like, but it does state that they may be "potentially interactive".
Much like clicking on colors on the CSS panel allows you to swap between rgba and hex, I could see the display of TypedArrays and DataViews being interactive, including a "hexdump" view.
I agree. It sounds like this isn't something that would require adding a new method to Console. Also Chrome does not sound willing to implement (given pfeldman@'s status:WontFix), and @bgrins seems to believe that could be done in DevTools with no real effect on Console.