Major enhancements to browser automation and debugging capabilities: **Console Capture Features:** - Add console output file option (CLI, env var, session config) - Enhanced CDP console capture for service worker messages - Browser-level security warnings and mixed content errors - Network failure and loading error capture - All console contexts written to structured log files - Chrome extension for comprehensive console message interception **Offline Mode Support:** - Add browser_set_offline tool for DevTools-equivalent offline mode - Integrate offline mode into browser_configure tool - Support for testing network failure scenarios and service worker behavior **Extension Management:** - Improved extension installation messaging about session persistence - Console capture extension with debugger API access - Clear communication about extension lifecycle to MCP clients **Technical Implementation:** - CDP session management across multiple domains (Runtime, Network, Security, Log) - Service worker context console message interception - Browser context factory integration for offline mode - Pure Chromium configuration for optimal extension support All features provide MCP clients with powerful debugging capabilities equivalent to Chrome DevTools console and offline functionality.
50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
// Content script for console capture extension
|
|
console.log('Console Capture Extension: Content script loaded');
|
|
|
|
// Listen for console messages from background script
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
if (request.type === 'CONSOLE_MESSAGE') {
|
|
const message = request.message;
|
|
|
|
// Forward to window for Playwright to access
|
|
window.postMessage({
|
|
type: 'PLAYWRIGHT_CONSOLE_CAPTURE',
|
|
consoleMessage: message
|
|
}, '*');
|
|
|
|
console.log('Console Capture Extension: Forwarded message:', message);
|
|
}
|
|
});
|
|
|
|
// Also capture any window-level console messages that might be missed
|
|
const originalConsole = {
|
|
log: window.console.log,
|
|
warn: window.console.warn,
|
|
error: window.console.error,
|
|
info: window.console.info
|
|
};
|
|
|
|
function wrapConsoleMethod(method, level) {
|
|
return function(...args) {
|
|
// Call original method
|
|
originalConsole[method].apply(window.console, args);
|
|
|
|
// Forward to Playwright
|
|
window.postMessage({
|
|
type: 'PLAYWRIGHT_CONSOLE_CAPTURE',
|
|
consoleMessage: {
|
|
type: level,
|
|
text: args.map(arg => String(arg)).join(' '),
|
|
location: `content-script:${new Error().stack?.split('\n')[2]?.match(/:(\d+):/)?.[1] || 0}`,
|
|
source: 'content-wrapper',
|
|
timestamp: Date.now()
|
|
}
|
|
}, '*');
|
|
};
|
|
}
|
|
|
|
// Wrap console methods
|
|
window.console.log = wrapConsoleMethod('log', 'log');
|
|
window.console.warn = wrapConsoleMethod('warn', 'warning');
|
|
window.console.error = wrapConsoleMethod('error', 'error');
|
|
window.console.info = wrapConsoleMethod('info', 'info'); |