GeminiBot commited on
Commit
0fbfbaf
·
1 Parent(s): a118953

Aggressive fix for iframe contentDocument null error

Browse files
Files changed (1) hide show
  1. src/duckai.ts +14 -2
src/duckai.ts CHANGED
@@ -28,14 +28,26 @@ export class DuckAI {
28
  window.chrome = { runtime: {} };
29
 
30
  // Fix for 'Cannot read properties of null (reading 'contentDocument')'
31
- // Some challenge scripts create an iframe and immediately access contentDocument
 
 
 
 
 
 
 
 
 
 
 
32
  const originalCreateElement = window.document.createElement;
33
  window.document.createElement = function(tagName: string) {
34
  const element = originalCreateElement.call(this, tagName);
35
  if (tagName.toLowerCase() === 'iframe') {
36
  try {
 
37
  Object.defineProperty(element, 'contentDocument', {
38
- get: () => window.document, // Return main document as fallback or a dummy
39
  configurable: true
40
  });
41
  Object.defineProperty(element, 'contentWindow', {
 
28
  window.chrome = { runtime: {} };
29
 
30
  // Fix for 'Cannot read properties of null (reading 'contentDocument')'
31
+ // Aggressive Patch: Modify the prototype directly
32
+ Object.defineProperty(window.HTMLIFrameElement.prototype, 'contentDocument', {
33
+ get: function() { return window.document; },
34
+ configurable: true
35
+ });
36
+
37
+ Object.defineProperty(window.HTMLIFrameElement.prototype, 'contentWindow', {
38
+ get: function() { return window; },
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) {
45
  const element = originalCreateElement.call(this, tagName);
46
  if (tagName.toLowerCase() === 'iframe') {
47
  try {
48
+ // Ensure properties are set on the instance as well
49
  Object.defineProperty(element, 'contentDocument', {
50
+ get: () => window.document,
51
  configurable: true
52
  });
53
  Object.defineProperty(element, 'contentWindow', {