GeminiBot
commited on
Commit
·
02bd6b6
1
Parent(s):
add57ca
Inject globals into eval scope to fix undefined document error
Browse files- src/duckai.ts +9 -12
src/duckai.ts
CHANGED
|
@@ -161,20 +161,17 @@ export class DuckAI {
|
|
| 161 |
// Immortal DOM patches (already applied above) are good.
|
| 162 |
|
| 163 |
// Execute script directly in the window context
|
| 164 |
-
//
|
| 165 |
-
const result = mockWindow.eval(`
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
}
|
| 172 |
-
`);
|
| 173 |
|
| 174 |
if (!result || !result.client_hashes) {
|
| 175 |
-
// If result is null, maybe the script put the result in a global variable?
|
| 176 |
-
// Sometimes DDG scripts do that. Let's check window.result or similar if needed.
|
| 177 |
-
// But for now, throw detailed error
|
| 178 |
throw new Error("Script executed but returned invalid result (no client_hashes)");
|
| 179 |
}
|
| 180 |
|
|
|
|
| 161 |
// Immortal DOM patches (already applied above) are good.
|
| 162 |
|
| 163 |
// Execute script directly in the window context
|
| 164 |
+
// Explicitly define globals for the script scope to prevent 'undefined' errors
|
| 165 |
+
const result = await mockWindow.eval(`
|
| 166 |
+
var window = this;
|
| 167 |
+
var document = this.document;
|
| 168 |
+
var navigator = this.navigator;
|
| 169 |
+
var screen = this.screen;
|
| 170 |
+
|
| 171 |
+
${jsScript}
|
| 172 |
+
`) as any;
|
| 173 |
|
| 174 |
if (!result || !result.client_hashes) {
|
|
|
|
|
|
|
|
|
|
| 175 |
throw new Error("Script executed but returned invalid result (no client_hashes)");
|
| 176 |
}
|
| 177 |
|