ai-debug-local-mcp
Version:
🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh
72 lines • 2.99 kB
JavaScript
export class DebugInjector {
/**
* Inject debugging code into the page for event tracking and monitoring
*/
async injectDebugging(page, framework) {
// Inject framework-agnostic debugging
await page.addInitScript(() => {
window.__AI_DEBUG__ = {
events: [],
recordEvent: function (type, data) {
this.events.push({
type,
data,
timestamp: new Date().toISOString()
});
}
};
// Monitor console
const originalLog = console.log;
const originalError = console.error;
const originalWarn = console.warn;
console.log = function (...args) {
window.__AI_DEBUG__.recordEvent('console.log', { args });
return originalLog.apply(console, args);
};
console.error = function (...args) {
window.__AI_DEBUG__.recordEvent('console.error', { args });
return originalError.apply(console, args);
};
console.warn = function (...args) {
window.__AI_DEBUG__.recordEvent('console.warn', { args });
return originalWarn.apply(console, args);
};
// Monitor clicks
document.addEventListener('click', (e) => {
const target = e.target;
window.__AI_DEBUG__.recordEvent('click', {
selector: target.tagName + (target.id ? '#' + target.id : '') + (target.className ? '.' + target.className.split(' ').join('.') : ''),
text: target.textContent?.substring(0, 50)
});
}, true);
// Monitor DOM mutations
window.__DOM_CHANGED__ = false;
const observer = new MutationObserver(() => {
window.__DOM_CHANGED__ = true;
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true
});
});
// Framework-specific instrumentation
if (framework === 'phoenix') {
await page.addInitScript(() => {
const checkLiveSocket = setInterval(() => {
const liveSocket = window.liveSocket;
if (liveSocket) {
clearInterval(checkLiveSocket);
// Monitor LiveView events
const originalPush = liveSocket.push;
liveSocket.push = function (event) {
window.__AI_DEBUG__.recordEvent('phoenix.push', { event });
return originalPush.apply(this, arguments);
};
}
}, 100);
});
}
}
}
//# sourceMappingURL=debug-injector.js.map