feat: add live inspector button, deep API detail logging, and diagnostic report download
This commit is contained in:
+36
-28
@@ -40,39 +40,47 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
if (message.action === 'SCRAPE_DOM_FEED') {
|
||||
try {
|
||||
const domActivities = scrapeDomFeedCards();
|
||||
sendResponse({ success: true, activities: domActivities, htmlSample: document.body.innerHTML.substring(0, 5000) });
|
||||
} catch (err) {
|
||||
sendResponse({ success: false, error: err.message });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (message.action === 'INSPECT_LIVE_FEED') {
|
||||
(async () => {
|
||||
try {
|
||||
const studentId = message.studentId || detectCurrentStudentId();
|
||||
const apiListRes = await fetch(`https://schools.mybrightwheel.com/api/v1/students/${studentId}/activities?page_size=25`, {
|
||||
credentials: 'include',
|
||||
headers: { 'Accept': 'application/json' }
|
||||
}).then(r => r.json()).catch(e => ({ error: e.message }));
|
||||
|
||||
if (message.action === 'FETCH_WITH_CREDENTIALS') {
|
||||
fetch(message.url, {
|
||||
method: message.method || 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
...(message.headers || {})
|
||||
},
|
||||
credentials: 'include'
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) {
|
||||
const errorText = await res.text().catch(() => '');
|
||||
return sendResponse({ success: false, status: res.status, statusText: res.statusText, body: errorText });
|
||||
const rawActs = apiListRes?.activities || apiListRes?.items || [];
|
||||
|
||||
// Sample detail fetches for video, nap, checkin
|
||||
const sampleDetails = {};
|
||||
for (const act of rawActs.slice(0, 10)) {
|
||||
const type = act.activity_type || act.action_type || act.type;
|
||||
if (!sampleDetails[type] && act.id) {
|
||||
const detail = await fetch(`https://schools.mybrightwheel.com/api/v1/students/${studentId}/activities/${act.id}`, {
|
||||
credentials: 'include',
|
||||
headers: { 'Accept': 'application/json' }
|
||||
}).then(r => r.json()).catch(e => ({ error: e.message }));
|
||||
sampleDetails[type] = detail;
|
||||
}
|
||||
}
|
||||
const json = await res.json();
|
||||
sendResponse({ success: true, status: res.status, data: json });
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
const domCards = scrapeDomFeedCards();
|
||||
|
||||
sendResponse({
|
||||
success: true,
|
||||
studentId,
|
||||
apiSampleActivities: rawActs.slice(0, 10),
|
||||
sampleDetails,
|
||||
domCards: domCards.slice(0, 20),
|
||||
pageTitle: document.title,
|
||||
currentUrl: window.location.href
|
||||
});
|
||||
} catch (err) {
|
||||
sendResponse({ success: false, error: err.message });
|
||||
});
|
||||
}
|
||||
})();
|
||||
return true; // async
|
||||
}
|
||||
});
|
||||
|
||||
// DOM Scraper for Brightwheel Web Feed
|
||||
function scrapeDomFeedCards() {
|
||||
|
||||
Reference in New Issue
Block a user