Spaces:
Paused
Paused
File size: 2,115 Bytes
bcf46c3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | document.getElementById('scanBtn').addEventListener('click', async () => {
const statusDiv = document.getElementById('status');
const resultDiv = document.getElementById('result');
const detailsDiv = document.getElementById('details');
const scanBtn = document.getElementById('scanBtn');
statusDiv.textContent = "Capturing active tab...";
resultDiv.style.display = 'none';
resultDiv.className = '';
detailsDiv.textContent = '';
scanBtn.disabled = true;
try {
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
if (tabs.length === 0) {
throw new Error("No active tab found");
}
const activeTab = tabs[0];
const dataUrl = await chrome.tabs.captureVisibleTab(activeTab.windowId, { format: 'png' });
// Strip the data URL prefix if needed, or let the backend handle it.
// We send the raw Base64 image
const base64Image = dataUrl.split(',')[1] || dataUrl;
statusDiv.textContent = "Analyzing with PhishVision AI...";
// Call the live Node.js PhishVision endpoint
const response = await fetch('https://opticparse-1opticparse-node-sg.onrender.com/api/phishvision/scan', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ image_base64: base64Image })
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`API Error ${response.status}: ${errorText}`);
}
const data = await response.json();
statusDiv.textContent = "Analysis complete.";
resultDiv.style.display = 'block';
if (data.is_malicious || data.threat_level === "HIGH") {
resultDiv.textContent = "⚠️ MALICIOUS PAGE DETECTED";
resultDiv.classList.add('malicious');
} else {
resultDiv.textContent = "✅ PAGE APPEARS SAFE";
resultDiv.classList.add('safe');
}
if (data.analysis) {
detailsDiv.textContent = `Analysis: ${data.analysis}`;
}
} catch (err) {
statusDiv.textContent = `Error: ${err.message}`;
} finally {
scanBtn.disabled = false;
}
});
|