Default files for webcam and attempt for error log

This commit is contained in:
Ruben van de Ven 2020-09-28 11:04:10 +02:00
parent 8247385779
commit d437cde6da
2 changed files with 84 additions and 9 deletions

View file

@ -397,4 +397,77 @@ function transformPoint(p, cx, cy, angle) {
x: px * cos(-angle) - py * sin(-angle),
y: px * sin(-angle) + py * cos(-angle)
}
}
}
// error handling from consoleUtils.js::hijackConsoleErrorsScript
function getScriptOff(line) {
var offs = 0;
var l = 0;
var file = '';
for (var i=0; i<offs.length; i++) {
var n = offs[i][0];
if (n < line && n > l) {
l = n;
file = offs[i][1];
}
}
return [line - l, file];
}
// catch reference errors, via http://stackoverflow.com/a/12747364/2994108
window.onerror = function (msg, url, lineNumber, columnNo, error) {
var string = msg.toLowerCase();
var substring = "script error";
var data = {};
// if (url.match(${EXTERNAL_LINK_REGEX}) !== null && error.stack){
// var errorNum = error.stack.split('about:srcdoc:')[1].split(':')[0];
// var fileInfo = getScriptOff(errorNum);
// data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
// } else {
var fileInfo = getScriptOff(lineNumber);
data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
// }
window.parent.postMessage([{
log: [{
method: 'error',
data: [data],
id: Date.now().toString()
}],
source: fileInfo[1]
}], '*');
return false;
};
// catch rejected promises
window.onunhandledrejection = function (event) {
if (event.reason && event.reason.message && event.reason.stack){
var errorNum = event.reason.stack.split('about:srcdoc:')[1].split(':')[0];
var fileInfo = getScriptOff(errorNum);
var data = event.reason.message + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
window.parent.postMessage([{
log: [{
method: 'error',
data: [data],
id: Date.now().toString()
}],
source: fileInfo[1]
}], '*');
}
};
(function(){
const oldLog = console.log;
console.log = function () {
const err = new Error();
const logSrc = err.stack.split("\n")[1];
window.parent.postMessage([{
log: [{
method: 'log',
data: arguments,
id: Date.now().toString()
}],
source: logSrc
}], '*');
oldLog.apply(console, arguments);
};
})();

View file

@ -1,17 +1,19 @@
const defaultSketch = `function setup() {
createCanvas(400, 400);
}
const defaultSketch = `// liveUpdate
function draw() {
background(220);
}`;
function drawMask(detection) {
stroke('red');
strokeWeight(2);
rect(detection.box.x, detection.box.y, detection.box.width, detection.box.height)
}
`;
const defaultHTML =
`<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/addons/p5.sound.min.js"></script>
<script src="/assets/p5.js"></script>
<script src="/assets/ml5.js"></script>
<script src="/assets/webcam.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />