bhollis / jsonview

A web extension that helps you view JSON documents in the browser.
http://jsonview.com
MIT License
1.54k stars 227 forks source link

expand/collapse icons showing as weird unicode characters #218

Closed joachim-n closed 3 months ago

joachim-n commented 3 months ago

Describe the bug

The collapse/expand icons are showing as unicode characters. See screenshot:

Screenshot 2024-08-12 at 15 06 31

**What browser are you using?***

Firefox 129.0 on MacOS 13.5.1

Where did you install JSONView from? No idea, sorry. Firefox add-ons says JSONView 3.0.1 with homepage https://jsonview.com/.

UWesthaus commented 3 months ago

I have the same issue since a long time on Firefox 129.0.2 (64 bit) on Windows 10.

The error is here: moz-extension://cb57a05e-6369-4338-86f0-180e62f5dfca/viewer.css

grafik

But I am unable to find or correct the file.

stanio commented 3 months ago

The error is here: moz-extension://cb57a05e-6369-4338-86f0-180e62f5dfca/viewer.css

It is not the only/main issue. I've built a patched version, adding at the top of viwer.css:

@charset "UTF-8";

This fixes the expand/collapse icons, but non-ASCII content is still garbled (note the japanese value):

Bad CSS-fix Good
Bad CSS-fix Good

All shots use example.json downloaded and served from a local web server. Both are served with:

Content-type: application/json

The "Good" is the original example.json that appears to start with UTF-8 BOM – this one results in correct expand/collapse icons and content w/o my extension patch. In the "Bad" and "CSS-fix" ones, I have removed the UTF-8 BOM from the file content. The latter has the suggested CSS fix applied to the extension.

stanio commented 3 months ago

In the "Bad" and "CSS-fix" ones, I have removed the UTF-8 BOM from the file content.

Funny enough, when I open the file via file: it shows just fine.

stanio commented 3 months ago

I think this is the main problem:

https://github.com/bhollis/jsonview/blob/a10aae50e75732c545c2dbabe771adeea36aa657/src/background-firefox.ts#L27-L29

The content type should have charset added when changed to text/*:

                header.value = "text/plain; charset=UTF-8";
stanio commented 3 months ago

The content type should have charset added when changed to text/*...

Also, changing the content type appears unnecessary when the Firefox built-in viewer is disabled explicitly by the user (about:config):

devtools.jsonview.enabled = false
stanio commented 3 months ago

Fixed for me using JSONView 3.0.2 in Firefox.