GeminiBot
commited on
Commit
·
5a61756
1
Parent(s):
0fbfbaf
Implement Immortal DOM to prevent null pointer crashes in challenge script
Browse files- src/duckai.ts +18 -0
src/duckai.ts
CHANGED
|
@@ -39,6 +39,24 @@ export class DuckAI {
|
|
| 39 |
configurable: true
|
| 40 |
});
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
// Also keep the createElement hook just in case
|
| 43 |
const originalCreateElement = window.document.createElement;
|
| 44 |
window.document.createElement = function(tagName: string) {
|
|
|
|
| 39 |
configurable: true
|
| 40 |
});
|
| 41 |
|
| 42 |
+
// IMMORTAL DOM Strategy: Never return null
|
| 43 |
+
const originalGetElementById = window.document.getElementById;
|
| 44 |
+
window.document.getElementById = function(id: string) {
|
| 45 |
+
const el = originalGetElementById.call(this, id);
|
| 46 |
+
if (el) return el;
|
| 47 |
+
// Return a dummy div if not found to prevent crash
|
| 48 |
+
return window.document.createElement('div');
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
const originalQuerySelector = window.document.querySelector;
|
| 52 |
+
window.document.querySelector = function(selector: string) {
|
| 53 |
+
try {
|
| 54 |
+
const el = originalQuerySelector.call(this, selector);
|
| 55 |
+
if (el) return el;
|
| 56 |
+
} catch(e) {}
|
| 57 |
+
return window.document.createElement('div');
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
// Also keep the createElement hook just in case
|
| 61 |
const originalCreateElement = window.document.createElement;
|
| 62 |
window.document.createElement = function(tagName: string) {
|