Skip to content

Commit 71b6ffc

Browse files
committed
Actually we don't need to transform the document
1 parent a6d30ab commit 71b6ffc

File tree

4 files changed

+4
-43
lines changed

4 files changed

+4
-43
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## JSONView 2.6.0
1+
## JSONView 2.6.1
22

33
- Restore JSONView's ability to work in Firefox without having to manually disable the built-in JSON viewer.
44

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
3-
"version": "2.6.0",
3+
"version": "2.6.1",
44
"name": "jsonview",
55
"title": "JSONView",
66
"description": "View JSON documents in the browser.",

src/background.ts

+1-40
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,6 @@ function isRedirect(status: number) {
1515
return status >= 300 && status < 400;
1616
}
1717

18-
/**
19-
* Use the filterResponseData API to transform a JSON document to HTML. This
20-
* converts to the same HTML that Chrome does by default - it's only used in
21-
* Firefox.
22-
*/
23-
function transformResponseToJSON(details: chrome.webRequest.WebResponseHeadersDetails) {
24-
const filter = browser.webRequest.filterResponseData(details.requestId);
25-
26-
const dec = new TextDecoder("utf-8");
27-
const enc = new TextEncoder();
28-
let content = "";
29-
30-
filter.ondata = (event) => {
31-
content += dec.decode(event.data, { stream: true });
32-
};
33-
34-
filter.onstop = (_event: Event) => {
35-
content += dec.decode();
36-
const outputDoc = `<!DOCTYPE html><html><head><meta charset="utf-8"></head><body><pre>${escape(
37-
content
38-
)}</pre></body></html>`;
39-
40-
filter.write(enc.encode(outputDoc));
41-
filter.disconnect();
42-
};
43-
}
44-
45-
function escape(s: string) {
46-
const lookup = {
47-
"&": "&amp;",
48-
'"': "&quot;",
49-
"'": "&apos;",
50-
"<": "&lt;",
51-
">": "&gt;",
52-
} as { [key: string]: string };
53-
return s.replace(/[&"'<>]/g, (c) => lookup[c]);
54-
}
55-
5618
function detectJSON(event: chrome.webRequest.WebResponseHeadersDetails) {
5719
if (!event.responseHeaders || isRedirect(event.statusCode)) {
5820
return;
@@ -65,8 +27,7 @@ function detectJSON(event: chrome.webRequest.WebResponseHeadersDetails) {
6527
) {
6628
jsonUrls.add(event.url);
6729
if (typeof browser !== "undefined" && "filterResponseData" in browser.webRequest) {
68-
header.value = "text/html";
69-
transformResponseToJSON(event);
30+
header.value = "text/plain";
7031
}
7132
}
7233
}

src/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "JSONView",
4-
"version": "2.6.0",
4+
"version": "2.6.1",
55
"description": "__MSG_extensionDescription__",
66
"author": "Benjamin Hollis",
77
"homepage_url": "https://jsonview.com/",

0 commit comments

Comments
 (0)