mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Address review items
This commit is contained in:
1 parent
0027752654
commit
fbea142bbb
4 files changed
+120
-78
No files matched your search
@@ -3,11 +3,12 @@
|
|||||||
* JSON-RPC based communication with parent page
|
* JSON-RPC based communication with parent page
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { storeOriginalConsole, overrideConsoleMethods, setupGlobalErrorHandlers, CONSOLE_METHODS } from './console-utils.js';
|
import { overrideConsoleMethods, setupGlobalErrorHandlers, CONSOLE_METHODS } from './console-utils.js';
|
||||||
|
|
||||||
class ConsoleInterceptor {
|
class ConsoleInterceptor {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.originalConsole = storeOriginalConsole();
|
// Use the original console stored by the inject script
|
||||||
|
this.originalConsole = window._originalConsole || console;
|
||||||
overrideConsoleMethods(this.originalConsole, this.sendConsoleMessage.bind(this));
|
overrideConsoleMethods(this.originalConsole, this.sendConsoleMessage.bind(this));
|
||||||
setupGlobalErrorHandlers(this.sendConsoleMessage.bind(this));
|
setupGlobalErrorHandlers(this.sendConsoleMessage.bind(this));
|
||||||
this.overrideWindowError();
|
this.overrideWindowError();
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
/**
|
||||||
|
* Early Console Interception Inject Script
|
||||||
|
* This script runs as early as possible to capture all console messages and errors
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ConsoleInterceptor {
|
||||||
|
constructor() {
|
||||||
|
this.originalConsole = {};
|
||||||
|
this.earlyErrors = [];
|
||||||
|
this.consoleMethods = [
|
||||||
|
'log', 'warn', 'error', 'info', 'debug', 'exception', 'assert',
|
||||||
|
'clear', 'count', 'countReset', 'dir', 'dirxml', 'group',
|
||||||
|
'groupCollapsed', 'groupEnd', 'table', 'time', 'timeEnd',
|
||||||
|
'timeLog', 'trace'
|
||||||
|
];
|
||||||
|
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.storeOriginalConsole();
|
||||||
|
this.overrideConsoleMethods();
|
||||||
|
this.setupGlobalErrorHandlers();
|
||||||
|
this.exposeToWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
storeOriginalConsole() {
|
||||||
|
this.consoleMethods.forEach(method => {
|
||||||
|
if (typeof console[method] === 'function') {
|
||||||
|
this.originalConsole[method] = console[method];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
overrideConsoleMethods() {
|
||||||
|
this.consoleMethods.forEach(method => {
|
||||||
|
if (typeof console[method] === 'function') {
|
||||||
|
console[method] = (...args) => {
|
||||||
|
this.handleConsoleCall(method, args);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleConsoleCall(method, args) {
|
||||||
|
// Try to call the original method
|
||||||
|
try {
|
||||||
|
this.originalConsole[method](...args);
|
||||||
|
} catch (e) {
|
||||||
|
// Original method failed, continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store error for later processing
|
||||||
|
if (method === 'error' || method === 'exception') {
|
||||||
|
this.earlyErrors.push({
|
||||||
|
level: method,
|
||||||
|
message: this.serializeArgs(args),
|
||||||
|
timestamp: Date.now(),
|
||||||
|
args: args
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
serializeArgs(args) {
|
||||||
|
return args.map(arg => {
|
||||||
|
if (typeof arg === 'object') {
|
||||||
|
try {
|
||||||
|
return JSON.stringify(arg);
|
||||||
|
} catch {
|
||||||
|
return String(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String(arg);
|
||||||
|
}).join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
setupGlobalErrorHandlers() {
|
||||||
|
// Handle window errors
|
||||||
|
window.addEventListener('error', (event) => {
|
||||||
|
this.earlyErrors.push({
|
||||||
|
level: 'error',
|
||||||
|
message: `Global Error: ${event.message}`,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
args: [{
|
||||||
|
filename: event.filename,
|
||||||
|
lineno: event.lineno,
|
||||||
|
colno: event.colno,
|
||||||
|
error: event.error ? event.error.message : 'No error object'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle unhandled promise rejections
|
||||||
|
window.addEventListener('unhandledrejection', (event) => {
|
||||||
|
this.earlyErrors.push({
|
||||||
|
level: 'error',
|
||||||
|
message: 'Unhandled Promise Rejection',
|
||||||
|
timestamp: Date.now(),
|
||||||
|
args: [event.reason]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exposeToWindow() {
|
||||||
|
// Store early errors for the main script to process
|
||||||
|
window._earlyConsoleErrors = this.earlyErrors;
|
||||||
|
|
||||||
|
// Store original console reference for the main script
|
||||||
|
window._originalConsole = this.originalConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the console interceptor immediately
|
||||||
|
new ConsoleInterceptor();
|
||||||
@@ -6,80 +6,7 @@
|
|||||||
<title>Site Preview</title>
|
<title>Site Preview</title>
|
||||||
<link rel="stylesheet" href="/_iframe-client.css">
|
<link rel="stylesheet" href="/_iframe-client.css">
|
||||||
<!-- Early console interception setup -->
|
<!-- Early console interception setup -->
|
||||||
<script>
|
<script src="/_iframe-console-intercept.js"></script>
|
||||||
// Set up console interception as early as possible to catch all errors
|
|
||||||
(function() {
|
|
||||||
// Store original console methods before any other script runs
|
|
||||||
const originalConsole = {};
|
|
||||||
const methods = ['log', 'warn', 'error', 'info', 'debug', 'exception', 'assert', 'clear', 'count', 'countReset', 'dir', 'dirxml', 'group', 'groupCollapsed', 'groupEnd', 'table', 'time', 'timeEnd', 'timeLog', 'trace'];
|
|
||||||
methods.forEach(method => {
|
|
||||||
if (typeof console[method] === 'function') {
|
|
||||||
originalConsole[method] = console[method];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Early error handlers to catch setup errors
|
|
||||||
const earlyErrors = [];
|
|
||||||
|
|
||||||
methods.forEach(method => {
|
|
||||||
if (typeof console[method] === 'function') {
|
|
||||||
console[method] = function(...args) {
|
|
||||||
try {
|
|
||||||
originalConsole[method](...args);
|
|
||||||
} catch (e) {
|
|
||||||
// Original method failed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store error for later processing
|
|
||||||
if (method === 'error' || method === 'exception') {
|
|
||||||
earlyErrors.push({
|
|
||||||
level: method,
|
|
||||||
message: args.map(arg => {
|
|
||||||
if (typeof arg === 'object') {
|
|
||||||
try {
|
|
||||||
return JSON.stringify(arg);
|
|
||||||
} catch {
|
|
||||||
return String(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return String(arg);
|
|
||||||
}).join(' '),
|
|
||||||
timestamp: Date.now(),
|
|
||||||
args: args
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up global error handlers
|
|
||||||
window.addEventListener('error', function(event) {
|
|
||||||
earlyErrors.push({
|
|
||||||
level: 'error',
|
|
||||||
message: `Global Error: ${event.message}`,
|
|
||||||
timestamp: Date.now(),
|
|
||||||
args: [{
|
|
||||||
filename: event.filename,
|
|
||||||
lineno: event.lineno,
|
|
||||||
colno: event.colno,
|
|
||||||
error: event.error ? event.error.message : 'No error object'
|
|
||||||
}]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
window.addEventListener('unhandledrejection', function(event) {
|
|
||||||
earlyErrors.push({
|
|
||||||
level: 'error',
|
|
||||||
message: 'Unhandled Promise Rejection',
|
|
||||||
timestamp: Date.now(),
|
|
||||||
args: [event.reason]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Store early errors for the main script to process
|
|
||||||
window._earlyConsoleErrors = earlyErrors;
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="loading">
|
<div class="loading">
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { useFS } from '@/hooks/useFS';
|
|||||||
import { Tabs, TabsContent } from '@/components/ui/tabs';
|
import { Tabs, TabsContent } from '@/components/ui/tabs';
|
||||||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { FolderOpen, ArrowLeft, Terminal, X } from 'lucide-react';
|
import { FolderOpen, ArrowLeft, X, Bug } from 'lucide-react';
|
||||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||||
import { GitStatusIndicator } from '@/components/GitStatusIndicator';
|
import { GitStatusIndicator } from '@/components/GitStatusIndicator';
|
||||||
import { BrowserAddressBar } from '@/components/ui/browser-address-bar';
|
import { BrowserAddressBar } from '@/components/ui/browser-address-bar';
|
||||||
@@ -440,7 +440,7 @@ export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
|||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant="ghost" size="sm" className="h-8 w-8 p-0 relative">
|
<Button variant="ghost" size="sm" className="h-8 w-8 p-0 relative">
|
||||||
<Terminal className="h-4 w-4" />
|
<Bug className="h-4 w-4" />
|
||||||
{consoleMessages.some(msg => msg.level === 'error') && (
|
{consoleMessages.some(msg => msg.level === 'error') && (
|
||||||
<span className="absolute bottom-0 left-0 h-2 w-2 bg-red-500 rounded-full"></span>
|
<span className="absolute bottom-0 left-0 h-2 w-2 bg-red-500 rounded-full"></span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in new issue
Block a user