Skip to content

Commit

Permalink
feat: support edge browser (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
rachpt authored Mar 26, 2024
1 parent 63507ad commit d3efef9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "JSON Viewer",
"version": "2.1.0",
"version": "2.1.1",
"description": "Port of Firefox's JSON Viewer",
"offline_enabled": true,
"homepage_url": "https://github.com/pd4d10/json-viewer",
Expand Down
19 changes: 15 additions & 4 deletions src/content-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ import { logDebug } from './utils'

// https://github.com/pd4d10/json-viewer/issues/28
// Since Chrome 117
const el = document.body.lastElementChild
const elPre = document.querySelector('body > pre')

if (el instanceof HTMLElement && el?.tagName === 'PRE') {
// Edge Browser
// https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/json-viewer/json-viewer
const elDiv = document.querySelector('body > div[hidden=true]')

if (elDiv instanceof HTMLElement) {
try {
JSON.parse(elDiv.innerText) // check if it's valid JSON
render(elDiv.innerText)
} catch (err) {
logDebug(err)
}
} else if (elPre instanceof HTMLElement) {
try {
JSON.parse(el.innerText) // check if it's valid JSON
render(el.innerText)
JSON.parse(elPre.innerText) // check if it's valid JSON
render(elPre.innerText)
} catch (err) {
logDebug(err)
}
Expand Down

0 comments on commit d3efef9

Please sign in to comment.