2024-09-03 18:33:35 +02:00
|
|
|
ISOTerminal.prototype.redirectConsole = function(handler){
|
|
|
|
const log = console.log;
|
|
|
|
const dir = console.dir;
|
|
|
|
const err = console.error;
|
|
|
|
const warn = console.warn;
|
|
|
|
console.log = (...args)=>{
|
|
|
|
const textArg = args[0];
|
|
|
|
handler(textArg+'\n');
|
|
|
|
log.apply(log, args);
|
|
|
|
};
|
|
|
|
console.error = (...args)=>{
|
2024-10-15 12:32:16 +02:00
|
|
|
const textArg = args[0]
|
2024-09-03 18:33:35 +02:00
|
|
|
handler( textArg+'\n', '\x1b[31merror\x1b[0m');
|
|
|
|
err.apply(log, args);
|
|
|
|
};
|
|
|
|
console.dir = (...args)=>{
|
2024-10-15 12:32:16 +02:00
|
|
|
const textArg = args[0]
|
2024-09-03 18:33:35 +02:00
|
|
|
handler( JSON.stringify(textArg,null,2)+'\n');
|
|
|
|
dir.apply(log, args);
|
|
|
|
};
|
|
|
|
console.warn = (...args)=>{
|
2024-10-15 12:32:16 +02:00
|
|
|
const textArg = args[0]
|
2024-09-03 18:33:35 +02:00
|
|
|
handler(textArg+'\n','\x1b[38;5;208mwarn\x1b[0m');
|
|
|
|
err.apply(log, args);
|
|
|
|
};
|
2024-09-06 18:02:54 +02:00
|
|
|
|
2024-09-03 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISOTerminal.addEventListener('emulator-started', function(){
|
|
|
|
|
|
|
|
this.redirectConsole( (str,prefix) => {
|
2024-09-16 13:28:28 +02:00
|
|
|
let finalStr = ""
|
|
|
|
prefix = prefix ? prefix+' ' : ' '
|
|
|
|
str.trim().split("\n").map( (line) => {
|
|
|
|
finalStr += '\x1b[38;5;165m/dev/browser: \x1b[0m'+prefix+line+'\n'
|
|
|
|
})
|
2024-10-18 13:50:56 +02:00
|
|
|
this.emit('append_file', ["/dev/browser/console",finalStr])
|
2024-09-03 18:33:35 +02:00
|
|
|
})
|
|
|
|
|
2024-09-06 18:02:54 +02:00
|
|
|
window.addEventListener('error', function(event) {
|
2024-09-25 15:58:40 +02:00
|
|
|
if( event.filename ){
|
|
|
|
console.error(event.filename+":"+event.lineno+":"+event.colno)
|
|
|
|
console.error(event.message);
|
|
|
|
console.error(event.error);
|
|
|
|
}else console.error(event)
|
2024-09-06 18:02:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener('unhandledrejection', function(event) {
|
2024-09-25 15:58:40 +02:00
|
|
|
console.error(event);
|
2024-09-06 18:02:54 +02:00
|
|
|
});
|
|
|
|
|
2024-09-03 18:33:35 +02:00
|
|
|
})
|