From d3efef9c539e5a9d97b4461aea5fdf121f2cb359 Mon Sep 17 00:00:00 2001 From: rachpt Date: Tue, 26 Mar 2024 20:55:36 +0800 Subject: [PATCH] feat: support edge browser (#29) --- chrome/manifest.json | 2 +- src/content-script.ts | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/chrome/manifest.json b/chrome/manifest.json index 8c001ab..57c5f17 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -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", diff --git a/src/content-script.ts b/src/content-script.ts index 6aeb49d..e1133d7 100644 --- a/src/content-script.ts +++ b/src/content-script.ts @@ -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) }