-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorHandler.js.html
More file actions
133 lines (106 loc) · 4.24 KB
/
errorHandler.js.html
File metadata and controls
133 lines (106 loc) · 4.24 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: errorHandler.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: errorHandler.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* js/errorHandler.js
* Handles error display and developer tools prevention.
* @module errorHandler
*/
// Retrieve error message from localStorage for display
const msg = localStorage.getItem("streamit_error");
// Get references to error display elements
const errorMessageEl = document.getElementById("error-message");
const errorCodeEl = document.getElementById("error-code");
// Parse error code from URL parameters
const urlParams = new URLSearchParams(window.location.search);
const paramCode = urlParams.get("code");
// Display error message if it exists in localStorage
if (msg && errorMessageEl) {
errorMessageEl.textContent = msg;
// Clean up localStorage after displaying the message
localStorage.removeItem("streamit_error");
} else if (msg && !errorMessageEl) {
// Clean up localStorage if error element doesn't exist
localStorage.removeItem("streamit_error");
}
// Display error code from URL parameter or default to 404
if (errorCodeEl) {
// Special formatting for 403 Forbidden errors
if (paramCode === "403") {
errorCodeEl.textContent = "403 - Forbidden";
} else
// Display the provided error code or default to 404
errorCodeEl.textContent = (paramCode || "404").toString();
}
/**
* Handles an error by storing the message and redirecting to the error page.
* @param {string} message - The error message to display.
* @param {number|string} [code=404] - The error code to display.
*/
function handleErrorAndRedirect(message, code = 404) {
localStorage.setItem("streamit_error", message);
const safeCode = (typeof code === "number" || typeof code === "string") ? code : 404;
window.location.href = `error.html?code=${encodeURIComponent(safeCode)}`;
}
// Prevent right-click context menu to protect content
document.addEventListener("contextmenu", (e) => e.preventDefault());
// Prevent common developer tools keyboard shortcuts
document.addEventListener("keydown", (e) => {
// Detect F12, Ctrl+Shift+I (Inspect), or Ctrl+U (View Source)
if (
e.key === "F12" ||
(e.ctrlKey && e.shiftKey && e.key.toLowerCase() === "i") ||
(e.ctrlKey && e.key.toLowerCase() === "u")
) {
e.preventDefault();
// Redirect to error page with 403 status
handleErrorAndRedirect(
"L'utilisation des outils de développement est interdite sur cette page.", 403
);
}
});
/**
* Detects if developer tools are open and redirects if so.
*/
(function detectDevTools() {
// Measure time taken by debugger statement (slow if devtools open)
const start = Date.now();
debugger; // This pauses execution if developer tools are open
if (Date.now() - start > 100) {
// Developer tools detected - redirect to error page
handleErrorAndRedirect(
"L'utilisation des outils de développement est interdite sur cette page.", 403
);
}
// Run detection check every second
setTimeout(detectDevTools, 1000);
})();</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-dataLoader.html">dataLoader</a></li><li><a href="module-display.html">display</a></li><li><a href="module-errorHandler.html">errorHandler</a></li><li><a href="module-main.html">main</a></li><li><a href="module-utils.html">utils</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Sun Feb 22 2026 09:55:20 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>