/** * Browser Pilot – Content Script * Captures console logs and provides DOM utilities. */ (function() { 'use strict'; if (window.__bpInjected) return; window.__bpInjected = true; // Console capture const orig = { log: console.log, warn: console.warn, error: console.error, info: console.info }; function hook(level) { return function(...args) { try { chrome.runtime.sendMessage({ type: 'CONSOLE_LOG', level, text: args.map(a => { try { return typeof a === 'object' ? JSON.stringify(a) : String(a); } catch { return String(a); } }).join(' ') }); } catch {} orig[level].apply(console, args); }; } console.log = hook('log'); console.warn = hook('warn'); console.error = hook('error'); console.info = hook('info'); window.addEventListener('error', e => { try { chrome.runtime.sendMessage({ type: 'CONSOLE_LOG', level: 'error', text: `${e.message} @ ${e.filename}:${e.lineno}` }); } catch {} }); window.addEventListener('unhandledrejection', e => { try { chrome.runtime.sendMessage({ type: 'CONSOLE_LOG', level: 'error', text: 'Unhandled: ' + e.reason }); } catch {} }); })();