Spaces:
Sleeping
Sleeping
fix(popup.js): async sidePanel.open, add CRITICAL severity count, show session_id source
Browse files- extension/popup.js +19 -9
extension/popup.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
/**
|
| 2 |
-
* ClauseGuard — Popup Script
|
| 3 |
* Shows user status (logged in / guest), scan results, usage.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
*/
|
| 5 |
|
| 6 |
document.addEventListener("DOMContentLoaded", async () => {
|
|
@@ -78,16 +82,17 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
| 78 |
try { await chrome.tabs.sendMessage(tab.id, { type: "TRIGGER_SCAN" }); } catch {} window.close();
|
| 79 |
});
|
| 80 |
|
| 81 |
-
//
|
| 82 |
const btnDetails = document.getElementById("btn-details");
|
| 83 |
-
if (btnDetails) btnDetails.addEventListener("click", () => {
|
| 84 |
-
try { chrome.sidePanel.open({ tabId: tab.id }); } catch {
|
|
|
|
| 85 |
});
|
| 86 |
|
| 87 |
// Login button
|
| 88 |
const btnLogin = document.getElementById("btn-login");
|
| 89 |
if (btnLogin) btnLogin.addEventListener("click", () => {
|
| 90 |
-
chrome.tabs.create({ url: "https://clauseguardweb.netlify.app/auth/login" });
|
| 91 |
});
|
| 92 |
});
|
| 93 |
|
|
@@ -110,15 +115,20 @@ function showResults(results) {
|
|
| 110 |
bar.className = "bar-fill " + (results.risk_score >= 60 ? "bar-red" : results.risk_score >= 30 ? "bar-amber" : "bar-green");
|
| 111 |
}
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
if (el("c-med")) el("c-med").textContent = counts.MEDIUM;
|
| 117 |
if (el("c-low")) el("c-low").textContent = counts.LOW;
|
| 118 |
|
| 119 |
// Show source indicator
|
| 120 |
const src = el("scan-source");
|
| 121 |
-
if (src) src.textContent = results.source === "api" ? "Legal-BERT" : results.source === "local" ? "Local" : "";
|
| 122 |
}
|
| 123 |
|
| 124 |
function updateUsage(usage) {
|
|
|
|
| 1 |
/**
|
| 2 |
+
* ClauseGuard — Popup Script v4.3
|
| 3 |
* Shows user status (logged in / guest), scan results, usage.
|
| 4 |
+
*
|
| 5 |
+
* FIXED v4.3: sidePanel.open() is properly awaited.
|
| 6 |
+
* FIXED v4.3: CRITICAL severity is now counted and displayed.
|
| 7 |
+
* FIXED v4.3: Shows scan source ("Legal-BERT" / "Local") accurately.
|
| 8 |
*/
|
| 9 |
|
| 10 |
document.addEventListener("DOMContentLoaded", async () => {
|
|
|
|
| 82 |
try { await chrome.tabs.sendMessage(tab.id, { type: "TRIGGER_SCAN" }); } catch {} window.close();
|
| 83 |
});
|
| 84 |
|
| 85 |
+
// FIX v4.3: Properly await async sidePanel.open() so errors are caught
|
| 86 |
const btnDetails = document.getElementById("btn-details");
|
| 87 |
+
if (btnDetails) btnDetails.addEventListener("click", async () => {
|
| 88 |
+
try { await chrome.sidePanel.open({ tabId: tab.id }); } catch(e) { console.warn("sidePanel.open failed:", e); }
|
| 89 |
+
window.close();
|
| 90 |
});
|
| 91 |
|
| 92 |
// Login button
|
| 93 |
const btnLogin = document.getElementById("btn-login");
|
| 94 |
if (btnLogin) btnLogin.addEventListener("click", () => {
|
| 95 |
+
chrome.tabs.create({ url: "https://clauseguardweb.netlify.app/auth/login" });
|
| 96 |
});
|
| 97 |
});
|
| 98 |
|
|
|
|
| 115 |
bar.className = "bar-fill " + (results.risk_score >= 60 ? "bar-red" : results.risk_score >= 30 ? "bar-amber" : "bar-green");
|
| 116 |
}
|
| 117 |
|
| 118 |
+
// FIX v4.3: Count CRITICAL severity too (backend can return it)
|
| 119 |
+
const counts = { CRITICAL: 0, HIGH: 0, MEDIUM: 0, LOW: 0 };
|
| 120 |
+
(results.results || []).forEach(r => (r.categories || []).forEach(c => {
|
| 121 |
+
if (counts[c.severity] !== undefined) counts[c.severity]++;
|
| 122 |
+
else counts.MEDIUM++; // Unknown severities default to MEDIUM
|
| 123 |
+
}));
|
| 124 |
+
// Merge CRITICAL into HIGH for display (popup only has 3 columns)
|
| 125 |
+
if (el("c-high")) el("c-high").textContent = counts.CRITICAL + counts.HIGH;
|
| 126 |
if (el("c-med")) el("c-med").textContent = counts.MEDIUM;
|
| 127 |
if (el("c-low")) el("c-low").textContent = counts.LOW;
|
| 128 |
|
| 129 |
// Show source indicator
|
| 130 |
const src = el("scan-source");
|
| 131 |
+
if (src) src.textContent = results.source === "api" ? "Legal-BERT" : results.source === "local" ? "Local (offline)" : "";
|
| 132 |
}
|
| 133 |
|
| 134 |
function updateUsage(usage) {
|