Fix school browser initialization and redirect detection; improve diagnostics

This commit is contained in:
Codex
2026-10-15 12:23:35 +08:00
parent 46e26ec548
commit a4c2df838e
20 changed files with 530 additions and 17 deletions
+38
View File
@@ -94,7 +94,45 @@ class DiagnosticLog {
add('navigation_$phase', fields: {'school': school, 'page': page});
}
void resourceFailure(
String school,
String? url, {
required String code,
int? status,
bool? mainFrame,
}) {
final uri = Uri.tryParse(url ?? '');
final path = uri?.path.toLowerCase() ?? '';
final kind = path.endsWith('.js')
? 'script'
: path.endsWith('.css')
? 'stylesheet'
: RegExp(r'\.(png|jpg|jpeg|gif|webp|svg|ico)$').hasMatch(path)
? 'image'
: 'document_or_request';
add(
'school_resource_failed',
fields: {
'school': school,
'phase': mainFrame == null
? 'unknown'
: mainFrame
? 'main'
: 'subresource',
'page': kind,
'code': code,
'status': status,
'type': uri?.scheme == 'http'
? 'http'
: uri?.scheme == 'https'
? 'https'
: 'other',
},
);
}
Future<void> attach(Directory directory) async {
// Retention and export use the same bounded, sanitized entries.
final file = File('${directory.path}/diagnostics-recent.json');
try {
if (await file.exists() && await file.length() <= maxBytes) {