-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
98 lines (91 loc) · 2.86 KB
/
Copy pathtest.html
File metadata and controls
98 lines (91 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Error Visualizer Test</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
button {
padding: 10px 15px;
margin: 10px;
background-color: #4a90e2;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #3a7bc8;
}
.error-container {
margin-top: 20px;
padding: 15px;
background-color: #f5f5f5;
border-radius: 4px;
}
</style>
</head>
<body>
<h1>JavaScript Error Visualizer Test Page</h1>
<p>This page contains various JavaScript errors to test the JavaScript Error Visualizer extension.</p>
<div>
<button id="runtime-error-btn">Trigger Runtime Error</button>
<button id="promise-error-btn">Trigger Promise Rejection</button>
<button id="console-error-btn">Trigger Console Error</button>
</div>
<div class="error-container" id="error-container">
<h2>Error Log:</h2>
<ul id="error-log"></ul>
</div>
<script>
// Function to log errors to the page
function logError(type, message) {
const errorLog = document.getElementById('error-log');
const errorItem = document.createElement('li');
errorItem.textContent = `${type}: ${message}`;
errorLog.appendChild(errorItem);
}
// Runtime Error
document.getElementById('runtime-error-btn').addEventListener('click', function() {
try {
// Intentional error: Accessing property of undefined
const obj = undefined;
obj.property = 'value';
} catch (e) {
logError('Caught Runtime Error', e.message);
// Re-throw to trigger uncaught error
throw new Error('Uncaught runtime error from button click');
}
});
// Promise Rejection
document.getElementById('promise-error-btn').addEventListener('click', function() {
// Create a promise that will be rejected
new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('Promise rejected from button click'));
}, 100);
}).catch(e => {
logError('Caught Promise Error', e.message);
// Re-throw to trigger unhandled rejection
throw e;
});
});
// Console Error
document.getElementById('console-error-btn').addEventListener('click', function() {
console.error('Console error from button click');
logError('Console Error', 'Console error from button click');
});
// Automatic error on page load (after a delay)
setTimeout(() => {
// This will cause a runtime error
document.getElementById('non-existent-element').style.color = 'red';
}, 2000);
</script>
</body>
</html>