GeminiBot commited on
Commit ·
add57ca
1
Parent(s): b3c25c2
Simplify eval context to fix undefined document error
Browse files149 unmodified lines150151152153154153154155156157158159160156157158159160161162161162163164165166167168169170171172173174165175176177178179180181149 unmodified lines return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="; };
// Ensure document is globally available for eval (mockWindow as any).document = mockWindow.document; // --- CONTEXT PREPARATION --- // Inject everything directly into the window context to avoid scope issues mockWindow.document = mockWindow.document; mockWindow.window = mockWindow; mockWindow.self = mockWindow; mockWindow.parent = mockWindow; mockWindow.top = mockWindow; const result = await mockWindow.eval(` (function() { const window = this; const document = this.document; ${jsScript} }).call(window) `) as any; // Immortal DOM patches (already applied above) are good. // Execute script directly in the window context // We wrap it in a try-catch block INSIDE the eval to capture script errors const result = mockWindow.eval(` try { ${jsScript} } catch(e) { console.error("Script Eval Error:", e); null; } `); if (!result || !result.client_hashes) { throw new Error("Invalid Challenge Response"); // If result is null, maybe the script put the result in a global variable? // Sometimes DDG scripts do that. Let's check window.result or similar if needed. // But for now, throw detailed error throw new Error("Script executed but returned invalid result (no client_hashes)"); }
result.client_hashes[0] = ua;src/duckai.ts+23-10