diff --git a/CHANGELOG.md b/CHANGELOG.md index 505cdd0..f529dc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## JSONView 2.6.0 +## JSONView 2.6.1 - Restore JSONView's ability to work in Firefox without having to manually disable the built-in JSON viewer. diff --git a/package.json b/package.json index c0451d4..249215b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "id": "jsonview@brh.numbera.com", - "version": "2.6.0", + "version": "2.6.1", "name": "jsonview", "title": "JSONView", "description": "View JSON documents in the browser.", diff --git a/src/background.ts b/src/background.ts index c312694..8e9cc1d 100644 --- a/src/background.ts +++ b/src/background.ts @@ -15,44 +15,6 @@ function isRedirect(status: number) { return status >= 300 && status < 400; } -/** - * Use the filterResponseData API to transform a JSON document to HTML. This - * converts to the same HTML that Chrome does by default - it's only used in - * Firefox. - */ -function transformResponseToJSON(details: chrome.webRequest.WebResponseHeadersDetails) { - const filter = browser.webRequest.filterResponseData(details.requestId); - - const dec = new TextDecoder("utf-8"); - const enc = new TextEncoder(); - let content = ""; - - filter.ondata = (event) => { - content += dec.decode(event.data, { stream: true }); - }; - - filter.onstop = (_event: Event) => { - content += dec.decode(); - const outputDoc = `
${escape( - content - )}`; - - filter.write(enc.encode(outputDoc)); - filter.disconnect(); - }; -} - -function escape(s: string) { - const lookup = { - "&": "&", - '"': """, - "'": "'", - "<": "<", - ">": ">", - } as { [key: string]: string }; - return s.replace(/[&"'<>]/g, (c) => lookup[c]); -} - function detectJSON(event: chrome.webRequest.WebResponseHeadersDetails) { if (!event.responseHeaders || isRedirect(event.statusCode)) { return; @@ -65,8 +27,7 @@ function detectJSON(event: chrome.webRequest.WebResponseHeadersDetails) { ) { jsonUrls.add(event.url); if (typeof browser !== "undefined" && "filterResponseData" in browser.webRequest) { - header.value = "text/html"; - transformResponseToJSON(event); + header.value = "text/plain"; } } } diff --git a/src/manifest.json b/src/manifest.json index 602ebfa..18eb84b 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "JSONView", - "version": "2.6.0", + "version": "2.6.1", "description": "__MSG_extensionDescription__", "author": "Benjamin Hollis", "homepage_url": "https://jsonview.com/",