feat: add live inspector button, deep API detail logging, and diagnostic report download
This commit is contained in:
@@ -263,6 +263,10 @@ function setupEventListeners() {
|
||||
checkSessionAndDiscoverStudents();
|
||||
});
|
||||
|
||||
if (el.inspectFeedBtn) {
|
||||
el.inspectFeedBtn.addEventListener('click', handleInspectFeed);
|
||||
}
|
||||
|
||||
el.setManualIdBtn.addEventListener('click', () => {
|
||||
const customId = el.manualStudentId.value.trim();
|
||||
if (!customId) return;
|
||||
@@ -308,6 +312,69 @@ function setupEventListeners() {
|
||||
});
|
||||
}
|
||||
|
||||
async function handleInspectFeed() {
|
||||
log('🔬 Inspecting live Brightwheel tab...', 'info');
|
||||
try {
|
||||
const [bwTab] = await chrome.tabs.query({ url: 'https://schools.mybrightwheel.com/*' });
|
||||
if (!bwTab || !bwTab.id) {
|
||||
log('No active Brightwheel tab found at schools.mybrightwheel.com. Please ensure the feed is open in a tab.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
chrome.tabs.sendMessage(bwTab.id, {
|
||||
action: 'INSPECT_LIVE_FEED',
|
||||
studentId: state.selectedStudentId
|
||||
}, (res) => {
|
||||
if (!res || !res.success) {
|
||||
log('Inspection response error: ' + (res?.error || 'Could not communicate with tab. Try refreshing the Brightwheel tab.'), 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
log(`✅ Live Inspection Complete for: ${res.currentUrl}`, 'success');
|
||||
log(`Page Title: "${res.pageTitle}"`, 'info');
|
||||
log(`DOM Cards Detected on Page: ${res.domCards?.length || 0}`, 'info');
|
||||
|
||||
if (res.domCards && res.domCards.length > 0) {
|
||||
res.domCards.slice(0, 3).forEach((dc, i) => {
|
||||
log(` [DOM Card ${i + 1}] Text: "${dc.raw_text.replace(/\s+/g, ' ').substring(0, 100)}..."`, 'info');
|
||||
});
|
||||
}
|
||||
|
||||
const acts = res.apiSampleActivities || [];
|
||||
log(`API Sample Activities Received: ${acts.length}`, 'success');
|
||||
|
||||
acts.forEach((a, idx) => {
|
||||
const type = a.activity_type || a.action_type || a.type;
|
||||
const presentKeys = Object.keys(a).filter(k => a[k] !== null && a[k] !== undefined && a[k] !== '');
|
||||
log(`[API Item ${idx + 1}] Type="${type}", Note="${a.note || a.body || ''}", Keys=[${presentKeys.join(', ')}]`, 'info');
|
||||
|
||||
if (type === 'ac_video' || type === 'video') {
|
||||
log(` -> Video payload: media=${JSON.stringify(a.media || null)}, video_url=${a.video_url || null}`, 'warn');
|
||||
}
|
||||
if (type === 'ac_nap' || type === 'nap') {
|
||||
log(` -> Nap payload: action_type=${a.action_type}, nap_start=${a.nap_start || a.start_time}, nap_end=${a.nap_end || a.end_time}, duration=${a.duration || a.duration_minutes}`, 'warn');
|
||||
}
|
||||
if (type === 'ac_checkin' || type === 'checkin') {
|
||||
log(` -> Checkin payload: action_type=${a.action_type}, signed_in_by=${a.signed_in_by || a.actor_name || a.guardian_name}, event_type=${a.event_type}`, 'warn');
|
||||
}
|
||||
});
|
||||
|
||||
// Automatically download inspection JSON report
|
||||
const blob = new Blob([JSON.stringify(res, null, 2)], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `brightwheel_inspection_${state.selectedStudentId}_${Date.now()}.json`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
log(`📁 Downloaded full inspection report to your Downloads folder (${(blob.size/1024).toFixed(1)} KB).`, 'success');
|
||||
});
|
||||
} catch (e) {
|
||||
log('Inspection error: ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Main Export Process Engine
|
||||
// -------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user