Repository navigation
Expand file tree
/
Copy pathui.js
More file actions
54 lines (46 loc) · 2.03 KB
/
Copy pathui.js
File metadata and controls
54 lines (46 loc) · 2.03 KB
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
export const $ = id => document.getElementById(id);
export function escHtml(value) {
return String(value)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"');
}
export function toast(message, type = 'info') {
const area = $('toast-area');
if (!area) return;
const el = document.createElement('div');
el.className = `toast ${type}`;
el.textContent = message;
area.appendChild(el);
setTimeout(() => el.remove(), 4000);
}
export function showError(message) {
const banner = $('error-banner');
if (!banner) return;
banner.textContent = message;
banner.style.display = 'block';
setTimeout(() => { banner.style.display = 'none'; }, 8000);
}
// ── Dev server side channel (devserver.py): only on localhost, never in production ──
const isDevServer = location.hostname === 'localhost';
function postToDevServer(path, text) {
if (!isDevServer) return;
void fetch(path, { method: 'POST', body: text, keepalive: true }).catch(() => { });
}
// A condensed report written to .agent/<name>.txt, for reading from the shell.
export function reportToDevServer(name, text) {
postToDevServer(`/__agent/report?name=${encodeURIComponent(name)}`, text);
}
// Uncaught errors, rejections and console.error, appended to .agent/browser.log.
if (isDevServer && !window.__devLogInstalled) {
window.__devLogInstalled = true;
const log = (kind, detail) => postToDevServer('/__agent/log', `${new Date().toISOString()} ${location.pathname} ${kind}: ${detail}`);
window.addEventListener('error', event => log('error', `${event.message} at ${event.filename}:${event.lineno}`));
window.addEventListener('unhandledrejection', event => log('rejection', event.reason?.stack || event.reason));
const consoleError = console.error.bind(console);
console.error = (...args) => {
log('console.error', args.map(arg => arg?.stack || (typeof arg === 'string' ? arg : JSON.stringify(arg))).join(' '));
consoleError(...args);
};
}