import React, { useEffect, useState } from "react"; function Results() { const [drmType, setDrmType] = useState(""); const [pssh, setPssh] = useState(""); const [licenseUrl, setLicenseUrl] = useState(""); const [keys, setKeys] = useState(""); useEffect(() => { chrome.storage.local.get( ["drmType", "latestPSSH", "latestLicenseRequest", "latestKeys"], (result) => { if (result.drmType) setDrmType(result.drmType); if (result.latestPSSH) setPssh(result.latestPSSH); if (result.latestLicenseRequest?.url) setLicenseUrl(result.latestLicenseRequest.url); if (result.latestKeys) { try { const parsed = Array.isArray(result.latestKeys) ? result.latestKeys : JSON.parse(result.latestKeys); setKeys(parsed); } catch (e) { console.error("Failed to parse keys:", e); setKeys([]); } } } ); const handleChange = (changes, area) => { if (area === "local") { if (changes.drmType) { setDrmType(changes.drmType.newValue); } if (changes.latestPSSH) { setPssh(changes.latestPSSH.newValue); } if (changes.latestLicenseRequest) { setLicenseUrl(changes.latestLicenseRequest.newValue.url); } if (changes.latestKeys) { setKeys(changes.latestKeys.newValue); } } }; chrome.storage.onChanged.addListener(handleChange); return () => chrome.storage.onChanged.removeListener(handleChange); }, []); const handleCapture = () => { // Reset stored values chrome.storage.local.set({ drmType: "None", latestPSSH: "None", latestLicenseRequest: { url: "None" }, latestKeys: [], }); // Get all normal windows to exclude your popup chrome.windows.getAll( { populate: true, windowTypes: ["normal"] }, (windows) => { if (!windows || windows.length === 0) { console.warn("No normal Chrome windows found"); return; } // Find the last focused normal window const lastFocusedWindow = windows.find((w) => w.focused) || windows[0]; if (!lastFocusedWindow) { console.warn("No focused normal window found"); return; } // Find the active tab in that window (that is a regular webpage) const activeTab = lastFocusedWindow.tabs.find( (tab) => tab.active && tab.url && /^https?:\/\//.test(tab.url) ); if (activeTab?.id) { chrome.tabs.reload(activeTab.id, () => { if (chrome.runtime.lastError) { console.error("Failed to reload tab:", chrome.runtime.lastError); } }); } else { console.warn("No active tab found in the last focused normal window"); } } ); }; return (
DRM Type
PSSH
License URL
Keys