@duckmind/dm-windows-x64 0.60.6 → 0.60.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dm.exe +0 -0
- package/extensions/.dm-extensions.json +70 -123
- package/extensions/dm-9router-ext/src/index.js +410 -5
- package/extensions/dm-caveman/extensions/caveman.js +283 -12
- package/extensions/dm-cliproxy/index.js +182 -2
- package/extensions/dm-cliproxy/scripts/check-config-migration.js +66 -8
- package/extensions/dm-cliproxy/src/apply.js +228 -1
- package/extensions/dm-cliproxy/src/cache.js +42 -1
- package/extensions/dm-cliproxy/src/commands.js +50 -2
- package/extensions/dm-cliproxy/src/compat.js +81 -1
- package/extensions/dm-cliproxy/src/config.js +192 -2
- package/extensions/dm-cliproxy/src/conflicts.js +46 -1
- package/extensions/dm-cliproxy/src/fetch-models.js +190 -1
- package/extensions/dm-cliproxy/src/fetch-usage.js +41 -1
- package/extensions/dm-cliproxy/src/log.js +23 -1
- package/extensions/dm-cliproxy/src/status-quota.js +77 -1
- package/extensions/dm-cliproxy/src/ui-frame.js +50 -1
- package/extensions/dm-cliproxy/src/ui-hub/hub.js +199 -2
- package/extensions/dm-cliproxy/src/ui-hub/index.js +26 -2
- package/extensions/dm-cliproxy/src/ui-hub/shell.js +46 -1
- package/extensions/dm-cliproxy/src/ui-hub/view-diagnostics.js +69 -1
- package/extensions/dm-cliproxy/src/ui-hub/view-models.js +379 -1
- package/extensions/dm-cliproxy/src/ui-hub/view-usage.js +106 -1
- package/extensions/dm-cliproxy/src/ui-picker/catalog.js +41 -1
- package/extensions/dm-cliproxy/src/ui-picker/mutate.js +115 -1
- package/extensions/dm-cliproxy/src/ui-picker/prompt-confirm.js +35 -1
- package/extensions/dm-cliproxy/src/ui-picker/prompt-name.js +62 -1
- package/extensions/dm-cliproxy/src/ui-picker/providers.js +45 -1
- package/extensions/dm-cliproxy/src/ui-picker/render-text.js +34 -1
- package/extensions/dm-cliproxy/src/ui-picker/rows.js +57 -1
- package/extensions/dm-cliproxy/src/ui-setup.js +260 -2
- package/extensions/dm-cliproxy/src/ui-usage.js +151 -1
- package/extensions/dm-cliproxy/src/usage-shared-cache.js +97 -1
- package/extensions/dm-context/src/context.js +144 -1
- package/extensions/dm-context/src/index.js +339 -7
- package/extensions/dm-context/src/utils.js +9 -1
- package/extensions/dm-cua/bin/browser-cua.mjs +73 -8
- package/extensions/dm-cua/index.js +75 -6
- package/extensions/dm-cua/src/browser-cua-lib.mjs +490 -6
- package/extensions/dm-cua/src/browser-install.mjs +331 -2
- package/extensions/dm-fff/src/index.js +688 -12
- package/extensions/dm-fff/src/query.js +60 -1
- package/extensions/dm-goal/src/goal.js +894 -23
- package/extensions/dm-image2/index.js +103 -9
- package/extensions/dm-image2/src/image-lib.mjs +1275 -8
- package/extensions/dm-subagents/install.mjs +62 -8
- package/extensions/dm-subagents/src/agents/agent-management.js +1190 -36
- package/extensions/dm-subagents/src/agents/agent-memory.js +216 -6
- package/extensions/dm-subagents/src/agents/agent-scope.js +5 -1
- package/extensions/dm-subagents/src/agents/agent-selection.js +20 -1
- package/extensions/dm-subagents/src/agents/agent-serializer.js +120 -5
- package/extensions/dm-subagents/src/agents/agents.js +1139 -11
- package/extensions/dm-subagents/src/agents/chain-serializer.js +299 -11
- package/extensions/dm-subagents/src/agents/frontmatter.js +65 -6
- package/extensions/dm-subagents/src/agents/identity.js +29 -1
- package/extensions/dm-subagents/src/agents/proactive-skills.js +141 -1
- package/extensions/dm-subagents/src/agents/skills.js +614 -6
- package/extensions/dm-subagents/src/extension/config.js +35 -2
- package/extensions/dm-subagents/src/extension/control-notices.js +69 -4
- package/extensions/dm-subagents/src/extension/doctor.js +172 -15
- package/extensions/dm-subagents/src/extension/fanout-child.js +158 -231
- package/extensions/dm-subagents/src/extension/index.js +521 -359
- package/extensions/dm-subagents/src/extension/rpc.js +266 -7
- package/extensions/dm-subagents/src/extension/schemas.js +275 -1
- package/extensions/dm-subagents/src/extension/tool-description.js +111 -6
- package/extensions/dm-subagents/src/intercom/intercom-bridge.js +126 -4
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +452 -5
- package/extensions/dm-subagents/src/intercom/result-intercom.js +319 -3
- package/extensions/dm-subagents/src/profiles/profiles.js +458 -3
- package/extensions/dm-subagents/src/runs/background/async-execution.js +834 -40
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +435 -14
- package/extensions/dm-subagents/src/runs/background/async-resume.js +334 -8
- package/extensions/dm-subagents/src/runs/background/async-status.js +313 -12
- package/extensions/dm-subagents/src/runs/background/chain-append.js +245 -2
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +136 -1
- package/extensions/dm-subagents/src/runs/background/completion-batcher.js +94 -1
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.js +54 -1
- package/extensions/dm-subagents/src/runs/background/control-channel.js +190 -1
- package/extensions/dm-subagents/src/runs/background/fleet-view.js +483 -17
- package/extensions/dm-subagents/src/runs/background/notify.js +129 -3
- package/extensions/dm-subagents/src/runs/background/parallel-groups.js +34 -1
- package/extensions/dm-subagents/src/runs/background/result-watcher.js +236 -6
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.js +76 -4
- package/extensions/dm-subagents/src/runs/background/run-status.js +427 -23
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.js +487 -4
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +306 -9
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +2849 -73
- package/extensions/dm-subagents/src/runs/background/top-level-async.js +5 -1
- package/extensions/dm-subagents/src/runs/background/wait.js +206 -11
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.js +1013 -12
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.js +980 -101
- package/extensions/dm-subagents/src/runs/foreground/execution.js +1165 -45
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +3157 -222
- package/extensions/dm-subagents/src/runs/shared/acceptance.js +835 -3
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.js +104 -1
- package/extensions/dm-subagents/src/runs/shared/completion-guard.js +116 -3
- package/extensions/dm-subagents/src/runs/shared/dm-args.js +208 -1
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +90 -1
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.js +282 -1
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +148 -1
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.js +305 -1
- package/extensions/dm-subagents/src/runs/shared/model-fallback.js +194 -1
- package/extensions/dm-subagents/src/runs/shared/model-scope.js +65 -1
- package/extensions/dm-subagents/src/runs/shared/nested-events.js +851 -8
- package/extensions/dm-subagents/src/runs/shared/nested-path.js +41 -1
- package/extensions/dm-subagents/src/runs/shared/nested-render.js +105 -1
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.js +81 -4
- package/extensions/dm-subagents/src/runs/shared/run-history.js +51 -4
- package/extensions/dm-subagents/src/runs/shared/single-output.js +149 -8
- package/extensions/dm-subagents/src/runs/shared/structured-output.js +58 -1
- package/extensions/dm-subagents/src/runs/shared/subagent-control.js +166 -5
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +329 -13
- package/extensions/dm-subagents/src/runs/shared/tool-budget.js +73 -1
- package/extensions/dm-subagents/src/runs/shared/turn-budget.js +47 -4
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.js +196 -1
- package/extensions/dm-subagents/src/runs/shared/worktree.js +435 -3
- package/extensions/dm-subagents/src/shared/artifacts.js +92 -2
- package/extensions/dm-subagents/src/shared/atomic-json.js +55 -1
- package/extensions/dm-subagents/src/shared/child-transcript.js +167 -5
- package/extensions/dm-subagents/src/shared/file-coalescer.js +25 -1
- package/extensions/dm-subagents/src/shared/fork-context.js +147 -4
- package/extensions/dm-subagents/src/shared/formatters.js +98 -7
- package/extensions/dm-subagents/src/shared/jsonl-writer.js +56 -2
- package/extensions/dm-subagents/src/shared/model-info.js +62 -1
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.js +68 -1
- package/extensions/dm-subagents/src/shared/session-identity.js +6 -1
- package/extensions/dm-subagents/src/shared/session-tokens.js +39 -2
- package/extensions/dm-subagents/src/shared/settings.js +198 -11
- package/extensions/dm-subagents/src/shared/status-format.js +53 -1
- package/extensions/dm-subagents/src/shared/types.js +184 -6
- package/extensions/dm-subagents/src/shared/utils.js +462 -2
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +288 -1
- package/extensions/dm-subagents/src/slash/prompt-workflows.js +297 -7
- package/extensions/dm-subagents/src/slash/slash-bridge.js +118 -1
- package/extensions/dm-subagents/src/slash/slash-commands.js +1287 -31
- package/extensions/dm-subagents/src/slash/slash-live-state.js +240 -4
- package/extensions/dm-subagents/src/tui/render-helpers.js +64 -1
- package/extensions/dm-subagents/src/tui/render.js +1542 -4
- package/extensions/dm-usage/index.js +1294 -9
- package/extensions/greedysearch-dm/bin/cdp-greedy.mjs +40 -9
- package/extensions/greedysearch-dm/bin/cdp-headless.mjs +5 -2
- package/extensions/greedysearch-dm/bin/cdp-visible.mjs +5 -2
- package/extensions/greedysearch-dm/bin/cdp.mjs +896 -30
- package/extensions/greedysearch-dm/bin/gschrome.mjs +30 -2
- package/extensions/greedysearch-dm/bin/kill-visible.mjs +7 -2
- package/extensions/greedysearch-dm/bin/launch-visible.mjs +13 -2
- package/extensions/greedysearch-dm/bin/launch.mjs +282 -10
- package/extensions/greedysearch-dm/bin/mcp.mjs +386 -361
- package/extensions/greedysearch-dm/bin/search.mjs +620 -540
- package/extensions/greedysearch-dm/bin/visible.mjs +22 -2
- package/extensions/greedysearch-dm/extractors/bing-copilot.mjs +329 -579
- package/extensions/greedysearch-dm/extractors/chatgpt.mjs +301 -583
- package/extensions/greedysearch-dm/extractors/common.mjs +408 -32
- package/extensions/greedysearch-dm/extractors/consensus.mjs +376 -365
- package/extensions/greedysearch-dm/extractors/consent.mjs +303 -14
- package/extensions/greedysearch-dm/extractors/gemini.mjs +228 -592
- package/extensions/greedysearch-dm/extractors/google-ai.mjs +78 -499
- package/extensions/greedysearch-dm/extractors/logically.mjs +270 -347
- package/extensions/greedysearch-dm/extractors/perplexity.mjs +243 -581
- package/extensions/greedysearch-dm/extractors/selectors.mjs +32 -1
- package/extensions/greedysearch-dm/extractors/semantic-scholar.mjs +130 -317
- package/extensions/greedysearch-dm/index.js +123 -23
- package/extensions/greedysearch-dm/src/fetcher.mjs +576 -2
- package/extensions/greedysearch-dm/src/formatters/results.js +95 -10
- package/extensions/greedysearch-dm/src/formatters/sources.js +57 -1
- package/extensions/greedysearch-dm/src/formatters/synthesis.js +49 -1
- package/extensions/greedysearch-dm/src/github.mjs +222 -7
- package/extensions/greedysearch-dm/src/reddit.mjs +145 -14
- package/extensions/greedysearch-dm/src/search/browser-lifecycle.mjs +340 -9
- package/extensions/greedysearch-dm/src/search/challenge-detect.mjs +112 -4
- package/extensions/greedysearch-dm/src/search/chrome.mjs +486 -285
- package/extensions/greedysearch-dm/src/search/constants.mjs +109 -8
- package/extensions/greedysearch-dm/src/search/defaults.mjs +10 -1
- package/extensions/greedysearch-dm/src/search/engines.mjs +79 -9
- package/extensions/greedysearch-dm/src/search/fetch-source.mjs +441 -349
- package/extensions/greedysearch-dm/src/search/file-sources.mjs +29 -7
- package/extensions/greedysearch-dm/src/search/minimize.mjs +86 -1
- package/extensions/greedysearch-dm/src/search/output.mjs +51 -5
- package/extensions/greedysearch-dm/src/search/paths.mjs +48 -1
- package/extensions/greedysearch-dm/src/search/pdf.mjs +63 -2
- package/extensions/greedysearch-dm/src/search/port-pid.mjs +69 -1
- package/extensions/greedysearch-dm/src/search/progress.mjs +109 -2
- package/extensions/greedysearch-dm/src/search/query.mjs +21 -1
- package/extensions/greedysearch-dm/src/search/recovery.mjs +49 -1
- package/extensions/greedysearch-dm/src/search/research.mjs +2227 -458
- package/extensions/greedysearch-dm/src/search/scale-aware.mjs +61 -11
- package/extensions/greedysearch-dm/src/search/simple-research.mjs +396 -805
- package/extensions/greedysearch-dm/src/search/sources.mjs +412 -1
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +127 -12
- package/extensions/greedysearch-dm/src/search/synthesis.mjs +202 -12
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +209 -23
- package/extensions/greedysearch-dm/src/tools/shared.js +226 -10
- package/extensions/greedysearch-dm/src/utils/content.mjs +35 -4
- package/extensions/greedysearch-dm/src/utils/helpers.js +22 -1
- package/extensions/greedysearch-dm/src/utils/node-runtime.mjs +10 -1
- package/extensions/greedysearch-dm/src/utils/system-cmds.mjs +61 -1
- package/package.json +1 -1
|
@@ -1,571 +1,39 @@
|
|
|
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
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} catch(e) {}
|
|
36
|
-
if (!_origWrite) return undefined;
|
|
37
|
-
try { return await _origWrite(items); }
|
|
38
|
-
catch (_) { return undefined; }
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
`;await c(["eval",e,r])}async function D(e,t,r,n={}){let{timeoutMs:a=2600}=n,l=n.retryClick!=null?n.retryClick:Math.floor(a*0.4),i=String.raw`
|
|
42
|
-
new Promise((resolve) => {
|
|
43
|
-
const _deadline = Date.now() + ${a};
|
|
44
|
-
const _retryAt = Date.now() + ${l};
|
|
45
|
-
let _retried = false;
|
|
46
|
-
function _click() { try { ${t}; } catch(_) {} }
|
|
47
|
-
function _poll() {
|
|
48
|
-
const val = window.${r};
|
|
49
|
-
if (val) { resolve(val); return; }
|
|
50
|
-
if (!_retried && Date.now() >= _retryAt) {
|
|
51
|
-
_retried = true;
|
|
52
|
-
_click();
|
|
53
|
-
}
|
|
54
|
-
if (Date.now() < _deadline) { setTimeout(_poll, 100); }
|
|
55
|
-
else { resolve(window.${r} || ''); }
|
|
56
|
-
}
|
|
57
|
-
_click();
|
|
58
|
-
_poll();
|
|
59
|
-
})
|
|
60
|
-
`;return await c(["eval",e,i],a+5000).catch(()=>"")}async function ie(e){await c(["evalraw",e,"Page.addScriptToEvaluateOnNewDocument",JSON.stringify({source:`
|
|
61
|
-
(function() {
|
|
62
|
-
// ── Runtime.enable / CDP detection masking ──────────────
|
|
63
|
-
try { delete window.__REBROWSER_RUNTIME_ENABLE; } catch(_) {}
|
|
64
|
-
try { delete window.__REBROWSER_DEVTOOLS; } catch(_) {}
|
|
65
|
-
try { delete window.__nightmare; } catch(_) {}
|
|
66
|
-
try { delete window.__phantom; } catch(_) {}
|
|
67
|
-
try { delete window.callPhantom; } catch(_) {}
|
|
68
|
-
try { delete window._phantom; } catch(_) {}
|
|
69
|
-
try { delete window.Buffer; } catch(_) {}
|
|
70
|
-
|
|
71
|
-
// Real Chrome without automation should not expose navigator.webdriver at all.
|
|
72
|
-
// A literal false or an own-property getter returning undefined is itself a
|
|
73
|
-
// common stealth tell; remove both instance and prototype properties when the
|
|
74
|
-
// descriptor is configurable (as it is with --disable-blink-features).
|
|
75
|
-
try { delete navigator.webdriver; } catch(_) {}
|
|
76
|
-
try { delete Navigator.prototype.webdriver; } catch(_) {}
|
|
77
|
-
Object.defineProperty(navigator, 'vendor', { get: () => 'Google Inc.', configurable: true });
|
|
78
|
-
Object.defineProperty(navigator, 'platform', { get: () => 'Win32', configurable: true });
|
|
79
|
-
Object.defineProperty(navigator, 'maxTouchPoints', { get: () => 0, configurable: true });
|
|
80
|
-
Object.defineProperty(navigator, 'pdfViewerEnabled', { get: () => true, configurable: true });
|
|
81
|
-
Object.defineProperty(navigator, 'productSub', { get: () => '20030107', configurable: true });
|
|
82
|
-
Object.defineProperty(navigator, 'product', { get: () => 'Gecko', configurable: true });
|
|
83
|
-
var __greedyMimeTypes = null;
|
|
84
|
-
function __makeMimeTypes() {
|
|
85
|
-
var pdf = { type: 'application/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null };
|
|
86
|
-
var textPdf = { type: 'text/pdf', suffixes: 'pdf', description: 'Portable Document Format', enabledPlugin: null };
|
|
87
|
-
try { Object.setPrototypeOf(pdf, MimeType.prototype); } catch(_) {}
|
|
88
|
-
try { Object.setPrototypeOf(textPdf, MimeType.prototype); } catch(_) {}
|
|
89
|
-
var m = [pdf, textPdf];
|
|
90
|
-
try { Object.setPrototypeOf(m, MimeTypeArray.prototype); } catch(_) {}
|
|
91
|
-
m.item = function item(i) { return this[i] || null; };
|
|
92
|
-
m.namedItem = function namedItem(name) { return Array.prototype.find.call(this, function(x) { return x && x.type === name; }) || null; };
|
|
93
|
-
return m;
|
|
94
|
-
}
|
|
95
|
-
Object.defineProperty(navigator, 'plugins', {
|
|
96
|
-
get: () => {
|
|
97
|
-
__greedyMimeTypes = __greedyMimeTypes || __makeMimeTypes();
|
|
98
|
-
var plugin0 = { name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format' };
|
|
99
|
-
var plugin1 = { name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '' };
|
|
100
|
-
var plugin2 = { name: 'Native Client', filename: 'internal-nacl-plugin', description: '' };
|
|
101
|
-
try { Object.setPrototypeOf(plugin0, Plugin.prototype); } catch(_) {}
|
|
102
|
-
try { Object.setPrototypeOf(plugin1, Plugin.prototype); } catch(_) {}
|
|
103
|
-
try { Object.setPrototypeOf(plugin2, Plugin.prototype); } catch(_) {}
|
|
104
|
-
var p = [plugin0, plugin1, plugin2];
|
|
105
|
-
p.item = function item(i) { return this[i] || null; };
|
|
106
|
-
p.namedItem = function namedItem(name) { return Array.prototype.find.call(this, function(x) { return x && x.name === name; }) || null; };
|
|
107
|
-
p.refresh = function refresh() {};
|
|
108
|
-
try { Object.setPrototypeOf(p, PluginArray.prototype); } catch(_) {}
|
|
109
|
-
try {
|
|
110
|
-
__greedyMimeTypes[0].enabledPlugin = p[0];
|
|
111
|
-
__greedyMimeTypes[1].enabledPlugin = p[0];
|
|
112
|
-
} catch(_) {}
|
|
113
|
-
return p;
|
|
114
|
-
},
|
|
115
|
-
configurable: true,
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperty(navigator, 'mimeTypes', {
|
|
118
|
-
get: () => {
|
|
119
|
-
__greedyMimeTypes = __greedyMimeTypes || __makeMimeTypes();
|
|
120
|
-
return __greedyMimeTypes;
|
|
121
|
-
},
|
|
122
|
-
configurable: true,
|
|
123
|
-
});
|
|
124
|
-
Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'], configurable: true });
|
|
125
|
-
try {
|
|
126
|
-
Object.defineProperty(navigator, 'connection', { get: () => ({ effectiveType: '4g', rtt: 50, downlink: 10, downlinkMax: Infinity, saveData: false }), configurable: true });
|
|
127
|
-
} catch(_) {}
|
|
128
|
-
if (!navigator.mediaDevices) {
|
|
129
|
-
Object.defineProperty(navigator, 'mediaDevices', {
|
|
130
|
-
get: () => ({
|
|
131
|
-
enumerateDevices: () => Promise.resolve([
|
|
132
|
-
{ deviceId: 'default', kind: 'audioinput', label: '', groupId: 'default' },
|
|
133
|
-
{ deviceId: 'default', kind: 'audiooutput', label: '', groupId: 'default' },
|
|
134
|
-
{ deviceId: '', kind: 'videoinput', label: '', groupId: '' },
|
|
135
|
-
]),
|
|
136
|
-
getUserMedia: () => Promise.reject(new DOMException('NotAllowedError')),
|
|
137
|
-
getDisplayMedia: () => Promise.reject(new DOMException('NotAllowedError')),
|
|
138
|
-
}),
|
|
139
|
-
configurable: true,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
// ── Missing platform APIs (headless often lacks these) ─
|
|
143
|
-
try {
|
|
144
|
-
if (!navigator.share) {
|
|
145
|
-
navigator.share = function() { return Promise.reject(new Error('NotAllowedError')); };
|
|
146
|
-
}
|
|
147
|
-
} catch(_) {}
|
|
148
|
-
try {
|
|
149
|
-
if (!navigator.contentIndex) {
|
|
150
|
-
Object.defineProperty(navigator, 'contentIndex', { get: () => ({ add: function() {}, delete: function() {}, getAll: function() { return Promise.resolve([]); } }), configurable: true });
|
|
151
|
-
}
|
|
152
|
-
} catch(_) {}
|
|
153
|
-
|
|
154
|
-
if (!window.chrome) {
|
|
155
|
-
window.chrome = {
|
|
156
|
-
app: { isInstalled: false, InstallState: {}, RunningState: {} },
|
|
157
|
-
runtime: {
|
|
158
|
-
OnInstalledReason: {}, OnRestartRequiredReason: {}, PlatformArch: {}, PlatformNaclArch: {}, PlatformOs: {}, RequestUpdateCheckStatus: {},
|
|
159
|
-
connect: () => ({}), sendMessage: () => {}, onMessage: { addListener: () => {} }
|
|
160
|
-
},
|
|
161
|
-
loadTimes: function() { return { requestTime: 0, startLoadTime: Date.now() - 5000, commitLoadTime: Date.now() - 3000, finishDocumentLoadTime: Date.now() - 2000, finishLoadTime: Date.now() - 1000, firstPaintTime: Date.now() - 800, navigationType: 'Other', wasFetchedViaSpdy: true, wasNpnNegotiated: true, npnNegotiatedProtocol: 'h2', wasAlternateProtocolAvailable: false, connectionInfo: 'http/2' }; },
|
|
162
|
-
csi: function() { var t = Date.now(); return { onloadT: t - 2000, startE: t - 5000, pageT: 'back', tran: 2 }; },
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
var __greedyNativeFns = [];
|
|
166
|
-
function __markNative(fn) { try { __greedyNativeFns.push(fn); } catch(_) {} return fn; }
|
|
167
|
-
|
|
168
|
-
var origQuery = navigator.permissions?.query;
|
|
169
|
-
if (origQuery) {
|
|
170
|
-
navigator.permissions.query = __markNative(function query(params) {
|
|
171
|
-
if (params && params.name === 'notifications') return Promise.resolve({ state: Notification.permission || 'default', onchange: null });
|
|
172
|
-
return origQuery.apply(this, arguments);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
var getParam = WebGLRenderingContext.prototype.getParameter;
|
|
177
|
-
WebGLRenderingContext.prototype.getParameter = __markNative(function getParameter(p) {
|
|
178
|
-
if (p === 37445) return 'Intel Inc.';
|
|
179
|
-
if (p === 37446) return 'Intel Iris OpenGL Engine';
|
|
180
|
-
return getParam.call(this, p);
|
|
181
|
-
});
|
|
182
|
-
} catch(_) {}
|
|
183
|
-
// ── WebGL readPixels noise ──────────────────────────
|
|
184
|
-
// CreepJS and other fingerprinters draw content with WebGL and read back the
|
|
185
|
-
// rendered pixels. Adding subtle noise breaks rendering-based fingerprinting.
|
|
186
|
-
try {
|
|
187
|
-
var origReadPixels = WebGLRenderingContext.prototype.readPixels;
|
|
188
|
-
WebGLRenderingContext.prototype.readPixels = __markNative(function readPixels(x, y, width, height, format, type, pixels) {
|
|
189
|
-
var result = origReadPixels.call(this, x, y, width, height, format, type, pixels);
|
|
190
|
-
if (pixels && pixels.length > 0) {
|
|
191
|
-
pixels[0] ^= 1;
|
|
192
|
-
}
|
|
193
|
-
return result;
|
|
194
|
-
});
|
|
195
|
-
} catch(_) {}
|
|
196
|
-
Object.defineProperty(navigator, 'hardwareConcurrency', { get: () => 8, configurable: true });
|
|
197
|
-
Object.defineProperty(navigator, 'deviceMemory', { get: () => 8, configurable: true });
|
|
198
|
-
|
|
199
|
-
// ── Canvas fingerprint noise ─────────────────────────
|
|
200
|
-
// Headless rendering engines produce slightly different canvas output
|
|
201
|
-
// than headed Chrome. Subtle noise breaks hash-based fingerprinting.
|
|
202
|
-
try {
|
|
203
|
-
var __canvasNoise = ((Date.now() & 0xFF) | 1);
|
|
204
|
-
var origFill = CanvasRenderingContext2D.prototype.fillText;
|
|
205
|
-
CanvasRenderingContext2D.prototype.fillText = __markNative(function fillText() {
|
|
206
|
-
this.globalAlpha = 0.9995;
|
|
207
|
-
return origFill.apply(this, arguments);
|
|
208
|
-
});
|
|
209
|
-
} catch(_) {}
|
|
210
|
-
try {
|
|
211
|
-
var origStroke = CanvasRenderingContext2D.prototype.strokeText;
|
|
212
|
-
CanvasRenderingContext2D.prototype.strokeText = __markNative(function strokeText() {
|
|
213
|
-
this.globalAlpha = 0.9995;
|
|
214
|
-
return origStroke.apply(this, arguments);
|
|
215
|
-
});
|
|
216
|
-
} catch(_) {}
|
|
217
|
-
try {
|
|
218
|
-
var origToDataURL = HTMLCanvasElement.prototype.toDataURL;
|
|
219
|
-
HTMLCanvasElement.prototype.toDataURL = __markNative(function toDataURL() {
|
|
220
|
-
var ctx = this.getContext('2d');
|
|
221
|
-
if (ctx) {
|
|
222
|
-
// Spread noise across canvas to break hash-based fingerprinting.
|
|
223
|
-
// Uses a deterministic pattern so it's consistent per page load
|
|
224
|
-
// but varies between sessions.
|
|
225
|
-
var w = this.width, h = this.height;
|
|
226
|
-
if (w > 0 && h > 0) {
|
|
227
|
-
var imgData = ctx.getImageData(0, 0, Math.min(w, 4), Math.min(h, 4));
|
|
228
|
-
if (imgData && imgData.data) {
|
|
229
|
-
for (var __i = 0; __i < imgData.data.length; __i += 4) {
|
|
230
|
-
imgData.data[__i] ^= (__canvasNoise + __i) & 0xFF;
|
|
231
|
-
}
|
|
232
|
-
ctx.putImageData(imgData, 0, 0);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return origToDataURL.apply(this, arguments);
|
|
237
|
-
});
|
|
238
|
-
} catch(_) {}
|
|
239
|
-
|
|
240
|
-
// ── AudioContext fingerprint noise ────────────────────
|
|
241
|
-
// Headless Chrome's AudioContext produces slightly different output.
|
|
242
|
-
// Subtle noise breaks audio-based fingerprinting.
|
|
243
|
-
try {
|
|
244
|
-
var __audioSeed = ((Date.now() & 0x1F) | 1);
|
|
245
|
-
var origGetChannelData = AudioBuffer.prototype.getChannelData;
|
|
246
|
-
AudioBuffer.prototype.getChannelData = __markNative(function getChannelData(channel) {
|
|
247
|
-
var data = origGetChannelData.call(this, channel);
|
|
248
|
-
for (var __i = 0; __i < data.length; __i += 64) {
|
|
249
|
-
data[__i] *= 0.99999;
|
|
250
|
-
}
|
|
251
|
-
return data;
|
|
252
|
-
});
|
|
253
|
-
} catch(_) {}
|
|
254
|
-
|
|
255
|
-
// ── window outer dimensions ──────────────────────────
|
|
256
|
-
// outerWidth/Height = 0 in headless — a well-known bot signal.
|
|
257
|
-
// Mirror innerWidth/Height (set by --window-size flag) so the ratio is sane.
|
|
258
|
-
try {
|
|
259
|
-
if (!window.outerWidth) Object.defineProperty(window, 'outerWidth', { get: () => window.innerWidth || 1920, configurable: true });
|
|
260
|
-
if (!window.outerHeight) Object.defineProperty(window, 'outerHeight', { get: () => window.innerHeight || 1080, configurable: true });
|
|
261
|
-
} catch(_) {}
|
|
262
|
-
|
|
263
|
-
// ── screen properties ─────────────────────────────────
|
|
264
|
-
// Headless Chrome often reports an 800x600 screen even when the viewport is
|
|
265
|
-
// 1920x1080. Keep screen metrics internally consistent with our launch flags.
|
|
266
|
-
try {
|
|
267
|
-
Object.defineProperty(screen, 'width', { get: () => 1920, configurable: true });
|
|
268
|
-
Object.defineProperty(screen, 'height', { get: () => 1080, configurable: true });
|
|
269
|
-
Object.defineProperty(screen, 'availWidth', { get: () => 1920, configurable: true });
|
|
270
|
-
Object.defineProperty(screen, 'availHeight', { get: () => 1040, configurable: true });
|
|
271
|
-
Object.defineProperty(screen, 'colorDepth', { get: () => 24, configurable: true });
|
|
272
|
-
Object.defineProperty(screen, 'pixelDepth', { get: () => 24, configurable: true });
|
|
273
|
-
} catch(_) {}
|
|
274
|
-
|
|
275
|
-
// ── navigator.userAgentData (UA Client Hints) ─────────
|
|
276
|
-
// Derive version from the UA string already set by --user-agent flag so the
|
|
277
|
-
// two APIs are always consistent. Removes any "HeadlessChrome" brand entry.
|
|
278
|
-
try {
|
|
279
|
-
var _uaMajor = (navigator.userAgent.match(new RegExp('Chrome/([0-9]+)')) || [])[1] || '136';
|
|
280
|
-
var _uaFull = (navigator.userAgent.match(new RegExp('Chrome/([0-9.]+)')) || [])[1] || (_uaMajor + '.0.0.0');
|
|
281
|
-
var _brands = [
|
|
282
|
-
{ brand: 'Not)A;Brand', version: '99' },
|
|
283
|
-
{ brand: 'Google Chrome', version: _uaMajor },
|
|
284
|
-
{ brand: 'Chromium', version: _uaMajor },
|
|
285
|
-
];
|
|
286
|
-
Object.defineProperty(navigator, 'userAgentData', {
|
|
287
|
-
get: function() {
|
|
288
|
-
return {
|
|
289
|
-
brands: _brands, mobile: false, platform: 'Windows',
|
|
290
|
-
getHighEntropyValues: function() {
|
|
291
|
-
return Promise.resolve({
|
|
292
|
-
architecture: 'x86', bitness: '64',
|
|
293
|
-
brands: _brands,
|
|
294
|
-
fullVersionList: [
|
|
295
|
-
{ brand: 'Not)A;Brand', version: '99.0.0.0' },
|
|
296
|
-
{ brand: 'Google Chrome', version: _uaFull },
|
|
297
|
-
{ brand: 'Chromium', version: _uaFull },
|
|
298
|
-
],
|
|
299
|
-
mobile: false, model: '', platform: 'Windows',
|
|
300
|
-
platformVersion: '15.0.0', uaFullVersion: _uaFull, wow64: false,
|
|
301
|
-
});
|
|
302
|
-
},
|
|
303
|
-
toJSON: function() { return { brands: _brands, mobile: false, platform: 'Windows' }; },
|
|
304
|
-
};
|
|
305
|
-
},
|
|
306
|
-
configurable: true,
|
|
307
|
-
});
|
|
308
|
-
} catch(_) {}
|
|
309
|
-
|
|
310
|
-
// ── CDP Runtime serialization guard ──────────────────
|
|
311
|
-
// Sites detect CDP by putting a getter on Error.prototype.stack
|
|
312
|
-
// and checking if console.log triggers it (only happens when
|
|
313
|
-
// Runtime domain is enabled). We monkey-patch console methods to
|
|
314
|
-
// strip custom getters from arguments before they reach CDP.
|
|
315
|
-
try {
|
|
316
|
-
var _origLog = console.log, _origError = console.error,
|
|
317
|
-
_origWarn = console.warn, _origDebug = console.debug,
|
|
318
|
-
_origInfo = console.info;
|
|
319
|
-
var _safeArg = function(a) {
|
|
320
|
-
if (a instanceof Error) {
|
|
321
|
-
try { return new Error(a.message); } catch(_) { return a; }
|
|
322
|
-
}
|
|
323
|
-
return a;
|
|
324
|
-
};
|
|
325
|
-
console.log = __markNative(function log() { return _origLog.apply(console, Array.prototype.map.call(arguments, _safeArg)); });
|
|
326
|
-
console.error = __markNative(function error() { return _origError.apply(console, Array.prototype.map.call(arguments, _safeArg)); });
|
|
327
|
-
console.warn = __markNative(function warn() { return _origWarn.apply(console, Array.prototype.map.call(arguments, _safeArg)); });
|
|
328
|
-
console.debug = __markNative(function debug() { return _origDebug.apply(console, Array.prototype.map.call(arguments, _safeArg)); });
|
|
329
|
-
console.info = __markNative(function info() { return _origInfo.apply(console, Array.prototype.map.call(arguments, _safeArg)); });
|
|
330
|
-
} catch(_) {}
|
|
331
|
-
|
|
332
|
-
// ── Native function masking ──────────────────────────
|
|
333
|
-
// Patched APIs should not stringify as user-defined stealth code.
|
|
334
|
-
try {
|
|
335
|
-
var __nativeToString = Function.prototype.toString;
|
|
336
|
-
Function.prototype.toString = function toString() {
|
|
337
|
-
if (__greedyNativeFns.indexOf(this) !== -1) {
|
|
338
|
-
var name = this.name || '';
|
|
339
|
-
return 'function ' + name + '() { [native code] }';
|
|
340
|
-
}
|
|
341
|
-
return __nativeToString.call(this);
|
|
342
|
-
};
|
|
343
|
-
} catch(_) {}
|
|
344
|
-
})();
|
|
345
|
-
`})])}function N(e){if(!e)return[];let t=[],r=0;while(r<e.length&&t.length<10){let n=e.indexOf("[",r);if(n===-1)break;let a=e.indexOf("](",n);if(a===-1)break;let l=a+2,i=-1;for(let o=l;o<e.length;o++){let s=e[o];if(s===")"){i=o;break}if(/\s/.test(s))break}if(i!==-1){let o=e.slice(n+1,a),s=e.slice(l,i);if(/^https?:\/\//i.test(s)&&o){if(!t.some((f)=>f.url===s))t.push({title:o,url:s})}r=i+1}else r=n+1}return t}var $={postNav:800,postNavSlow:1200,postClick:300,postType:300,inputPoll:400,copyPoll:600,afterVerify:1500};function P(e){let t=e*0.2,r=U(-Math.floor(t),Math.floor(t)+1);return Math.max(50,Math.round(e+r))}async function M(e,t={}){let{timeout:r=20000,interval:n=600,stableRounds:a=3,selector:l="document.body",minLength:i=0,isStreamingExpr:o="false"}=t,s=String.raw`
|
|
346
|
-
new Promise((resolve, reject) => {
|
|
347
|
-
const _deadline = Date.now() + ${r};
|
|
348
|
-
const _baseInterval = ${n};
|
|
349
|
-
const _stableRounds = ${a};
|
|
350
|
-
const _minLength = ${i};
|
|
351
|
-
let _lastLen = -1;
|
|
352
|
-
let _stableCount = 0;
|
|
353
|
-
|
|
354
|
-
function _jitter(ms) {
|
|
355
|
-
return Math.max(50, ms + (Math.random() * ms * 0.4 - ms * 0.2));
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function _poll() {
|
|
359
|
-
try {
|
|
360
|
-
// Re-query DOM each tick — element may not exist at eval start
|
|
361
|
-
const el = ${l};
|
|
362
|
-
const cur = el?.textContent?.length ?? 0;
|
|
363
|
-
const streaming = ${o};
|
|
364
|
-
if (streaming) {
|
|
365
|
-
if (cur !== _lastLen) _lastLen = cur;
|
|
366
|
-
_stableCount = 0;
|
|
367
|
-
} else if (cur >= _minLength) {
|
|
368
|
-
if (cur === _lastLen) {
|
|
369
|
-
_stableCount++;
|
|
370
|
-
if (_stableCount >= _stableRounds) { resolve(cur); return; }
|
|
371
|
-
} else {
|
|
372
|
-
_lastLen = cur;
|
|
373
|
-
_stableCount = 0;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (Date.now() < _deadline) {
|
|
377
|
-
setTimeout(_poll, _jitter(_baseInterval));
|
|
378
|
-
} else {
|
|
379
|
-
if (_lastLen >= _minLength && !streaming) { resolve(_lastLen); }
|
|
380
|
-
else { reject(new Error('Generation did not stabilise within ${r}ms')); }
|
|
381
|
-
}
|
|
382
|
-
} catch(e) { reject(e); }
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
_poll();
|
|
386
|
-
})
|
|
387
|
-
`,f=await c(["eval",e,s],r+1e4),u=parseInt(f,10)||0;if(u>=i)return u;throw Error(`Generation did not stabilise within ${r}ms`)}async function I(e,t,r=15000,n=500){let a=String.raw`
|
|
388
|
-
new Promise((resolve) => {
|
|
389
|
-
const _deadline = Date.now() + ${r};
|
|
390
|
-
const _baseInterval = ${n};
|
|
391
|
-
|
|
392
|
-
function _jitter(ms) {
|
|
393
|
-
return Math.max(50, ms + (Math.random() * ms * 0.4 - ms * 0.2));
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
function _poll() {
|
|
397
|
-
try {
|
|
398
|
-
if (document.querySelector('${t}')) { resolve(true); return; }
|
|
399
|
-
if (Date.now() < _deadline) { setTimeout(_poll, _jitter(_baseInterval)); }
|
|
400
|
-
else { resolve(false); }
|
|
401
|
-
} catch(_) { resolve(false); }
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
_poll();
|
|
405
|
-
})
|
|
406
|
-
`;return await c(["eval",e,a],r+5000)==="true"}async function A(e){let t=e.indexOf("--stdin");if(t===-1)return e;let r=await new Promise((a)=>{let l="";process.stdin.setEncoding("utf8"),process.stdin.on("data",(i)=>l+=i),process.stdin.on("end",()=>a(l.trim()))}),n=[...e];return n[t]=r,n}function E(e){let t=e.includes("--short"),r=e.filter((o)=>o!=="--short"),n=r.indexOf("--tab"),a=n===-1?null:r[n+1];if(n!==-1)r=r.filter((o,s)=>s!==n&&s!==n+1);let l=r.indexOf("--locale"),i=l===-1?null:r[l+1];if(l!==-1)r=r.filter((o,s)=>s!==l&&s!==l+1);return{query:r.join(" "),tabPrefix:a,short:t,locale:i}}function j(e,t){if(!e.length||e[0]==="--help")process.stderr.write(t),process.exit(1)}function L(e,t,r=300){if(!t||e.length<=r)return e;let n=e.slice(0,r),a=n.lastIndexOf(" ");return a>0?`${n.slice(0,a)}…`:`${n}…`}function R(e){process.stdout.write(`${JSON.stringify(e,null,2)}
|
|
407
|
-
`)}function k({engine:e,mode:t="headless",clipboardEmpty:r=null,fallbackUsed:n=null,blockedBy:a=null,verificationResult:l=null,inputReady:i=null,durationMs:o=null,lastStage:s=null,stages:f=null}={}){return{engine:e,mode:t,clipboardEmpty:r,fallbackUsed:n,blockedBy:a,verificationResult:l,inputReady:i,durationMs:o,lastStage:s,stages:f}}function F(e,t=null){if(t){let r=JSON.stringify({_envelope:t,error:e.message});process.stdout.write(`${r}
|
|
408
|
-
`)}process.stderr.write(`Error: ${e.message}
|
|
409
|
-
`),process.exit(1)}import{randomInt as ae}from"node:crypto";import{existsSync as oe,readFileSync as le}from"node:fs";import se from"node:http";var ce=`
|
|
410
|
-
(function() {
|
|
411
|
-
// Google consent page (consent.google.com)
|
|
412
|
-
var g = document.querySelector('#L2AGLb, button[jsname="b3VHJd"], .tHlp8d');
|
|
413
|
-
if (g) { g.click(); return 'google'; }
|
|
414
|
-
|
|
415
|
-
// OneTrust (used by many sites including Stack Overflow)
|
|
416
|
-
var ot = document.querySelector('#onetrust-accept-btn-handler, .onetrust-accept-btn-handler');
|
|
417
|
-
if (ot) { ot.click(); return 'onetrust'; }
|
|
418
|
-
|
|
419
|
-
// Generic "accept all" / "agree" buttons
|
|
420
|
-
var btns = Array.from(document.querySelectorAll('button, a[role=button]'));
|
|
421
|
-
var accept = btns.find(b => /^(accept all|accept cookies|agree|i agree|got it|allow all|allow cookies)$/i.test(b.innerText?.trim()));
|
|
422
|
-
if (accept) { accept.click(); return 'generic:' + accept.innerText.trim(); }
|
|
423
|
-
|
|
424
|
-
return null;
|
|
425
|
-
})()
|
|
426
|
-
`,ue=`
|
|
427
|
-
(function() {
|
|
428
|
-
var url = document.location.href;
|
|
429
|
-
|
|
430
|
-
// --- Google "sorry" page (hard CAPTCHA, can't auto-solve) ---
|
|
431
|
-
if (url.includes('/sorry/') || url.includes('sorry.google')) return 'sorry-page';
|
|
432
|
-
|
|
433
|
-
// --- Microsoft account verification page ---
|
|
434
|
-
if (url.includes('login.microsoftonline.com') || url.includes('login.live.com') || url.includes('account.microsoft.com')) {
|
|
435
|
-
var msBtns = Array.from(document.querySelectorAll('button, input[type=submit], a'));
|
|
436
|
-
var msVerify = msBtns.find(b => /verify|continue|next/i.test(b.innerText?.trim() || b.value || ''));
|
|
437
|
-
if (msVerify) { msVerify.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:msVerify.innerText?.trim()||msVerify.value}); }
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
// --- Copilot / modal verification ---
|
|
441
|
-
var modal = document.querySelector('[role="dialog"], .b_modal, [class*="verify"], [class*="challenge"]');
|
|
442
|
-
if (modal) {
|
|
443
|
-
var modalBtns = Array.from(modal.querySelectorAll('button, a[role="button"], input[type="submit"]'));
|
|
444
|
-
var actionBtn = modalBtns.find(b => /^(continue|verify|submit|next|i agree|accept|got it)$/i.test(b.innerText?.trim() || b.value || ''));
|
|
445
|
-
if (actionBtn) { actionBtn.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:actionBtn.innerText?.trim()}); }
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// --- Turnstile / Cloudflare challenge iframe (return coordinates for humanClickXY) ---
|
|
449
|
-
var turnstileIframe = document.querySelector('iframe[src*="challenges.cloudflare.com"], iframe[src*="turnstile"], iframe[title*="challenge"]');
|
|
450
|
-
if (turnstileIframe) {
|
|
451
|
-
var r = turnstileIframe.getBoundingClientRect();
|
|
452
|
-
return JSON.stringify({t:'xy',x:r.left+30,y:r.top+r.height/2});
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// --- Cloudflare Turnstile widget inside closed shadow DOM (Copilot, etc.) ---
|
|
456
|
-
// The iframe is not queryable from main document, but the host container
|
|
457
|
-
// (#cf-turnstile) and the hidden response input are. When only the
|
|
458
|
-
// hidden response input matches (no #cf-turnstile host and no visible
|
|
459
|
-
// iframe), the actual challenge widget is rendered inside a closed
|
|
460
|
-
// shadow DOM and cannot be auto-clicked. Return a sentinel so callers
|
|
461
|
-
// know to surface this as needs-human verification instead of wasting
|
|
462
|
-
// time on a doomed waitForSelector.
|
|
463
|
-
var cfTurnstileHost = document.querySelector('#cf-turnstile');
|
|
464
|
-
if (cfTurnstileHost) {
|
|
465
|
-
var r2 = cfTurnstileHost.getBoundingClientRect();
|
|
466
|
-
return JSON.stringify({t:'xy',x:r2.left+r2.width/2,y:r2.top+r2.height/2});
|
|
467
|
-
}
|
|
468
|
-
// Hidden cf-chl-widget-*_response input present but no visible host:
|
|
469
|
-
// the widget is in closed shadow DOM. Signal this so handleVerification
|
|
470
|
-
// can return 'needs-human' rather than 'clear'.
|
|
471
|
-
var cfResponseInput = document.querySelector('input[name="cf-turnstile-response"], [id^="cf-chl-widget-"][id$="_response"]');
|
|
472
|
-
if (cfResponseInput && cfResponseInput.value === '') {
|
|
473
|
-
return 'cf-closed-shadow-dom';
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
// --- Cloudflare challenge page ---
|
|
477
|
-
var cfCheckbox = document.querySelector('#cf-stage input[type="checkbox"], .ctp-checkbox-container input');
|
|
478
|
-
if (cfCheckbox) { cfCheckbox.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:'cloudflare-checkbox'}); }
|
|
479
|
-
var cfBtn = document.querySelector('#challenge-form button, .cf-challenge button');
|
|
480
|
-
if (cfBtn) { cfBtn.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:cfBtn.innerText?.trim()}); }
|
|
481
|
-
|
|
482
|
-
// --- Microsoft "I am human" button ---
|
|
483
|
-
var msHumanBtn = document.querySelector('button[id*="i0"], button[id*="id__"]');
|
|
484
|
-
if (msHumanBtn && /verify|human|robot|continue/i.test(msHumanBtn.innerText?.trim())) {
|
|
485
|
-
msHumanBtn.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:msHumanBtn.innerText.trim()});
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// --- Generic verify/continue/proceed buttons (catch-all) ---
|
|
489
|
-
// IMPORTANT: exclude sign-in / OAuth buttons (e.g. "Continue with Google",
|
|
490
|
-
// "Continue with email", "Login or sign up for free"). These appear on
|
|
491
|
-
// many sites (Perplexity, ChatGPT, etc.) when the user isn't logged in,
|
|
492
|
-
// and clicking them triggers a sign-in flow that takes us to a login
|
|
493
|
-
// wall — a much worse outcome than the original search failure we were
|
|
494
|
-
// trying to recover from. The exclusion list must cover both OAuth
|
|
495
|
-
// providers AND generic "sign in / log in / with email" patterns.
|
|
496
|
-
var btns = Array.from(document.querySelectorAll('button, input[type=submit], a[role=button]'));
|
|
497
|
-
var verify = btns.find(b => {
|
|
498
|
-
var t = (b.innerText?.trim() || b.value || '').toLowerCase();
|
|
499
|
-
var isVerifyLike = (t === 'continue' || t === 'proceed' || t === 'next' ||
|
|
500
|
-
t.startsWith('verify ') || t.startsWith('human ') || t === 'i am human' || t.includes('robot check')) &&
|
|
501
|
-
!t.includes('verified') && !document.querySelector('iframe[src*="recaptcha"]');
|
|
502
|
-
if (!isVerifyLike) return false;
|
|
503
|
-
// Exclude OAuth / sign-in buttons to prevent accidental login flows
|
|
504
|
-
// — covers "Continue with Google", "Continue with Apple", "Continue
|
|
505
|
-
// with email", "Login or sign up", "Log in", "Sign in", "Sign up",
|
|
506
|
-
// "Single sign-on", and the visible panel "Login or sign up for free"
|
|
507
|
-
// text. The previous list missed "email" and "sso" which let the
|
|
508
|
-
// auto-click land on the email/SSO sign-in buttons on Perplexity's
|
|
509
|
-
// anonymous-mode homepage, navigating us into a login flow.
|
|
510
|
-
var isSignIn = new RegExp("sign.?in|log.?in|sign.?up|with\\s+(google|apple|email|github|facebook|microsoft|sso)|sso|auth", "i").test(t);
|
|
511
|
-
return !isSignIn;
|
|
512
|
-
});
|
|
513
|
-
if (verify) { verify.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:verify.innerText?.trim()||verify.value}); }
|
|
514
|
-
|
|
515
|
-
// --- Google reCAPTCHA checkbox ---
|
|
516
|
-
var recaptchaCheckbox = document.querySelector('.recaptcha-checkbox-unchecked, input[type=checkbox][id*="recaptcha"]');
|
|
517
|
-
if (recaptchaCheckbox) { recaptchaCheckbox.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:'recaptcha'}); }
|
|
518
|
-
|
|
519
|
-
return null;
|
|
520
|
-
})()
|
|
521
|
-
`,de=`
|
|
522
|
-
(function() {
|
|
523
|
-
var url = document.location.href;
|
|
524
|
-
var isVerifyPage = url.includes('/sorry/') ||
|
|
525
|
-
url.includes('challenges.cloudflare.com') ||
|
|
526
|
-
url.includes('login.microsoftonline.com') ||
|
|
527
|
-
document.querySelector('#challenge-running, #challenge-stage, .cf-turnstile, [role="dialog"]');
|
|
528
|
-
if (!isVerifyPage) return 'cleared';
|
|
529
|
-
|
|
530
|
-
var btns = Array.from(document.querySelectorAll('button, input[type=submit], a[role=button]'));
|
|
531
|
-
var btn = btns.find(b => {
|
|
532
|
-
var t = (b.innerText?.trim() || b.value || '').toLowerCase();
|
|
533
|
-
var isVerifyLike = t.includes('verify') || t.includes('human') || t.includes('robot') || t.includes('continue') || t.includes('next') || t.includes('submit');
|
|
534
|
-
if (!isVerifyLike) return false;
|
|
535
|
-
var isSignIn = /sign.in|log.in|google|microsoft|apple|facebook|github|auth/i.test(t);
|
|
536
|
-
return !isSignIn;
|
|
537
|
-
});
|
|
538
|
-
if (btn) { btn.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:btn.innerText?.trim()||btn.value}); }
|
|
539
|
-
|
|
540
|
-
var cf = document.querySelector('#cf-stage input[type="checkbox"], .cf-turnstile input');
|
|
541
|
-
if (cf) { cf.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:'turnstile'}); }
|
|
542
|
-
|
|
543
|
-
// Cloudflare Turnstile widget inside closed shadow DOM (detected via host container)
|
|
544
|
-
var cfTurnstileHost = document.querySelector('#cf-turnstile, [id^="cf-chl-widget-"]');
|
|
545
|
-
if (cfTurnstileHost) { return 'still-verifying'; }
|
|
546
|
-
|
|
547
|
-
var modal = document.querySelector('[role="dialog"], .b_modal, [class*="verify"]');
|
|
548
|
-
if (modal) {
|
|
549
|
-
var modalBtn = modal.querySelector('button, a[role="button"]');
|
|
550
|
-
if (modalBtn) { modalBtn.setAttribute('data-gs-verify','1'); return JSON.stringify({t:'sel',s:'[data-gs-verify="1"]',txt:modalBtn.innerText?.trim()}); }
|
|
1
|
+
import {
|
|
2
|
+
buildEnvelope,
|
|
3
|
+
cdp,
|
|
4
|
+
clickCopyAndAwaitClipboard,
|
|
5
|
+
formatAnswer,
|
|
6
|
+
getOrOpenTab,
|
|
7
|
+
handleError,
|
|
8
|
+
injectClipboardInterceptor,
|
|
9
|
+
jitter,
|
|
10
|
+
outputJson,
|
|
11
|
+
parseArgs,
|
|
12
|
+
parseSourcesFromMarkdown,
|
|
13
|
+
prepareArgs,
|
|
14
|
+
TIMING,
|
|
15
|
+
validateQuery,
|
|
16
|
+
waitForSelector,
|
|
17
|
+
waitForStreamComplete
|
|
18
|
+
} from "./common.mjs";
|
|
19
|
+
import { dismissConsent, handleVerification } from "./consent.mjs";
|
|
20
|
+
import { SELECTORS } from "./selectors.mjs";
|
|
21
|
+
const S = SELECTORS.perplexity;
|
|
22
|
+
const GLOBAL_VAR = "__pplxClipboard";
|
|
23
|
+
function findCopyButtonJsExpression() {
|
|
24
|
+
return `Array.from(document.querySelectorAll('button')).filter(b => b.innerHTML.includes('#pplx-icon-copy')).pop()`;
|
|
25
|
+
}
|
|
26
|
+
async function extractAnswerFromDom(tab, env) {
|
|
27
|
+
function _looksLikeAnswerText(text) {
|
|
28
|
+
const t = (text || "").trim();
|
|
29
|
+
if (t.length > 50)
|
|
30
|
+
return true;
|
|
31
|
+
return t.length >= 5 && /\s|[.,!?;:]/.test(t);
|
|
551
32
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
`)[0],l=await new Promise((s,f)=>{let u=se.get(`http://localhost:${a}/json/version`,(m)=>{let g="";m.on("data",(p)=>g+=p),m.on("end",()=>{try{s(JSON.parse(g))}catch{f(Error("bad JSON"))}})});u.on("error",f),u.setTimeout(1000,()=>{u.destroy(),f(Error("timeout"))})}),i=new globalThis.WebSocket(l.webSocketDebuggerUrl),o=0;await new Promise((s)=>{i.onopen=async()=>{let f=(g,p)=>new Promise((_)=>{let v=++o,d=(h)=>{if(JSON.parse(h.data).id===v)i.removeEventListener("message",d),_()};i.addEventListener("message",d),i.send(JSON.stringify({id:v,method:g,params:p}))}),u=e+y(-2,2),m=t+y(-2,2);await f("Input.dispatchMouseEvent",{type:"mouseMoved",x:u,y:m,button:"none"}),await new Promise((g)=>setTimeout(g,y(80,160))),await f("Input.dispatchMouseEvent",{type:"mousePressed",x:u,y:m,button:"left",clickCount:1}),await new Promise((g)=>setTimeout(g,y(30,80))),await f("Input.dispatchMouseEvent",{type:"mouseReleased",x:u+y(-1,1),y:m+y(-1,1),button:"left",clickCount:1}),setTimeout(()=>{i.close(),s()},200)},i.onerror=()=>s(),setTimeout(s,3000)})}async function W(e,t,r,n){let a=Number.parseFloat(r),l=Number.parseFloat(n);if(Number.isNaN(a)||Number.isNaN(l))throw Error(`humanClickXY: invalid coordinates (${r}, ${n})`);let i={button:"left",clickCount:1,modifiers:0},o=a+y(-3,3),s=l+y(-3,3);await t(["evalraw",e,"Input.dispatchMouseEvent",JSON.stringify({...i,type:"mouseMoved",x:o,y:s})]),await new Promise((p)=>setTimeout(p,y(80,180)));let f=a+y(-2,2),u=l+y(-2,2);await t(["evalraw",e,"Input.dispatchMouseEvent",JSON.stringify({...i,type:"mousePressed",x:f,y:u})]),await new Promise((p)=>setTimeout(p,y(30,90)));let m=f+y(-1,1),g=u+y(-1,1);return await t(["evalraw",e,"Input.dispatchMouseEvent",JSON.stringify({...i,type:"mouseReleased",x:m,y:g})]),await fe(a,l).catch(()=>{}),await new Promise((p)=>setTimeout(p,y(100,300))),`human-clicked at (${a.toFixed(0)}, ${l.toFixed(0)})`}async function ge(e,t,r){let n=await t(["eval",e,`(function() {
|
|
557
|
-
var el = document.querySelector('${r.replace(/\\/g,"\\\\").replace(/'/g,"\\'")}');
|
|
558
|
-
if (!el) return 'null';
|
|
559
|
-
var r = el.getBoundingClientRect();
|
|
560
|
-
return JSON.stringify({x: r.left + r.width / 2, y: r.top + r.height / 2, w: r.width, h: r.height});
|
|
561
|
-
})()`]).catch(()=>"null");if(!n||n==="null")return null;let a=JSON.parse(n);if(a.w===0||a.h===0||a.x===0&&a.y===0)return null;let{x:l,y:i}=a;return W(e,t,l,i)}function J(e,t,r){if(!r||r==="null"||r==="cleared"||r==="still-verifying"||r==="cf-closed-shadow-dom")return Promise.resolve("no-challenge");try{let n=JSON.parse(r);if(n.t==="sel"&&n.s)return process.stderr.write(`[greedysearch] Human-clicking "${n.txt}" via CDP...
|
|
562
|
-
`),ge(e,t,n.s).then((a)=>a!==null?"clicked":"cant-click");if(n.t==="xy"){if(!n.x&&!n.y)return Promise.resolve("cant-click");return process.stderr.write(`[greedysearch] Human-clicking at (${n.x.toFixed(0)}, ${n.y.toFixed(0)})...
|
|
563
|
-
`),W(e,t,n.x,n.y).then(()=>"clicked")}}catch{}return Promise.resolve("no-challenge")}async function me(e,t){let r=await t(["eval",e,ue]).catch(()=>null);if(r==="cf-closed-shadow-dom"){let n=await pe(e,t).catch(()=>null);if(n)return n;return r}if(r&&r!=="null")return r;return null}async function pe(e,t){if(typeof t!=="function")return null;await t(["evalraw",e,"DOM.enable","{}"]).catch(()=>{});let r=await t(["evalraw",e,"DOM.getDocument",JSON.stringify({depth:-1,pierce:!0})]).catch(()=>null);if(!r)return null;let n;try{n=JSON.parse(r)}catch{return null}if(n.error||!n.root)return null;let a=n.root;return await q(a,e,t)}async function q(e,t,r){if(!e)return null;let n=[];if(e.shadowRoots&&e.shadowRoots.length>0)for(let a of e.shadowRoots)n.push(a);if(e.children)for(let a of e.children)n.push(a);for(let a of n){if(a.nodeName==="IFRAME"){let i=a.attributes||[],o=i.indexOf("src"),s=o>=0?i[o+1]:"";if(s&&/challenges\.cloudflare\.com|turnstile/i.test(s)&&a.backendNodeId){let f=await r(["evalraw",t,"DOM.getBoxModel",JSON.stringify({backendNodeId:a.backendNodeId})]).catch(()=>null);if(!f)continue;let u;try{u=JSON.parse(f)}catch{continue}let m=u?.model?.content||u?.result?.model?.content;if(!m||m.length<8)continue;let g=m[0],p=m[1],_=m[4],v=m[5],d=_-g,h=v-p;if(d<50||h<20)continue;let w=g+d*0.25,x=p+h*0.5;return process.stderr.write(`[greedysearch] Found CF iframe via CDP pierce at (${g.toFixed(0)}, ${p.toFixed(0)}) ${d.toFixed(0)}x${h.toFixed(0)}, clicking checkbox at (${w.toFixed(0)}, ${x.toFixed(0)})
|
|
564
|
-
`),JSON.stringify({t:"xy",x:w,y:x})}}let l=await q(a,t,r);if(l)return l}return null}async function H(e,t,r=30000){let n=await me(e,t);if(!n)return"clear";if(n==="sorry-page"){process.stderr.write(`[greedysearch] Google CAPTCHA detected — please solve it in the browser window (waiting up to ${Math.floor(r/1000)}s)...
|
|
565
|
-
`);let l=Date.now()+r;while(Date.now()<l)if(await new Promise((i)=>setTimeout(i,2000)),!(await t(["eval",e,"document.location.href"]).catch(()=>"")).includes("/sorry/"))return"cleared-by-user";return"needs-human"}let a=await J(e,t,n);if(a==="clicked"){await new Promise((i)=>setTimeout(i,2000));let l=Date.now()+r;while(Date.now()<l){let i=await t(["eval",e,de]).catch(()=>null);if(i==="cleared"||!i||i==="null")return process.stderr.write(`[greedysearch] Verification cleared.
|
|
566
|
-
`),"clicked";if(i!=="still-verifying")await J(e,t,i),await new Promise((o)=>setTimeout(o,2000));else await new Promise((o)=>setTimeout(o,1500))}return process.stderr.write(`[greedysearch] Verification may require manual intervention.
|
|
567
|
-
`),"needs-human"}if(a==="cant-click")return process.stderr.write(`[greedysearch] Verification challenge detected but cannot be auto-clicked — please solve it manually in the visible browser window.
|
|
568
|
-
`),"needs-human";return"clear"}var B={perplexity:{input:"#ask-input",copyButton:null,sourceItem:"[data-pplx-citation-url]",sourceLink:"a",consent:"#onetrust-accept-btn-handler"},bing:{input:"#userInput",copyButton:'button[data-testid="copy-ai-message-button"]',sourceLink:'a[href^="http"][target="_blank"]',sourceExclude:"copilot.microsoft.com",consent:"#onetrust-accept-btn-handler"},google:{answerContainer:".pWvJNd",sourceLink:'a[href^="http"]',sourceExclude:["google.","gstatic","googleapis"],sourceHeadingParent:"[data-snhf]",consent:'#L2AGLb, button[jsname="b3VHJd"], .tHlp8d'},gemini:{input:"rich-textarea .ql-editor",copyButton:'button:has(mat-icon[data-mat-icon-name="copy"])',sendButton:'button:has(mat-icon[data-mat-icon-name="arrow_upward"]), [data-test-id="send-button"], .send-button',sourcesSidebarButton:"button.legacy-sources-sidebar-button",sourcesExclude:["gemini.google","gstatic","google.com/search"],citationButtonPattern:'button[aria-label*="citation from"]',citationNameRegex:/from\s{1,20}([^.]{1,200})\.\s/}};var b=B.perplexity,V="__pplxClipboard";function he(){return"Array.from(document.querySelectorAll('button')).filter(b => b.innerHTML.includes('#pplx-icon-copy')).pop()"}async function ye(e,t){function r(l){let i=(l||"").trim();if(i.length>50)return!0;return i.length>=5&&/\s|[.,!?;:]/.test(i)}if(await c(["eval",e,`new Promise((resolve) => {
|
|
33
|
+
const navResult = await cdp([
|
|
34
|
+
"eval",
|
|
35
|
+
tab,
|
|
36
|
+
`new Promise((resolve) => {
|
|
569
37
|
const _deadline = Date.now() + 8000;
|
|
570
38
|
function _checkNav() {
|
|
571
39
|
const url = document.location.href;
|
|
@@ -578,7 +46,15 @@ import{randomInt as U}from"node:crypto";import{spawn as Y}from"node:child_proces
|
|
|
578
46
|
}
|
|
579
47
|
}
|
|
580
48
|
_checkNav();
|
|
581
|
-
})`
|
|
49
|
+
})`
|
|
50
|
+
], 1e4).catch(() => "timeout");
|
|
51
|
+
if (navResult === "timeout") {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const domExtract = await cdp([
|
|
55
|
+
"eval",
|
|
56
|
+
tab,
|
|
57
|
+
`new Promise((resolve) => {
|
|
582
58
|
const _deadline = Date.now() + 5000;
|
|
583
59
|
function _looksLikeAnswerText(text) {
|
|
584
60
|
const t = (text || '').trim();
|
|
@@ -612,7 +88,7 @@ import{randomInt as U}from"node:crypto";import{spawn as Y}from"node:child_proces
|
|
|
612
88
|
|
|
613
89
|
// Strategy 3: Find the largest text block in the main content area
|
|
614
90
|
// (not in nav/aside/sidebar), positioned after the input.
|
|
615
|
-
const input = document.querySelector('${
|
|
91
|
+
const input = document.querySelector('${S.input}');
|
|
616
92
|
if (!input) return resolve(null);
|
|
617
93
|
const inputRect = input.getBoundingClientRect();
|
|
618
94
|
const main = document.querySelector('main, [role="main"], [class*="main-content"]') || document.body;
|
|
@@ -639,7 +115,19 @@ import{randomInt as U}from"node:crypto";import{spawn as Y}from"node:child_proces
|
|
|
639
115
|
} catch(e) { resolve(null); }
|
|
640
116
|
}
|
|
641
117
|
_tryExtract();
|
|
642
|
-
})`
|
|
118
|
+
})`
|
|
119
|
+
], 8000).catch(() => null);
|
|
120
|
+
if (!domExtract || domExtract === "null")
|
|
121
|
+
return null;
|
|
122
|
+
try {
|
|
123
|
+
const { answer, method } = JSON.parse(domExtract);
|
|
124
|
+
if (answer && _looksLikeAnswerText(answer)) {
|
|
125
|
+
env.fallbackUsed = `dom:${method}`;
|
|
126
|
+
env.clipboardEmpty = true;
|
|
127
|
+
const sourcesExtract = await cdp([
|
|
128
|
+
"eval",
|
|
129
|
+
tab,
|
|
130
|
+
`(() => {
|
|
643
131
|
const links = Array.from(document.querySelectorAll('a[href^="https://"]'))
|
|
644
132
|
.filter(a => {
|
|
645
133
|
const href = a.href || '';
|
|
@@ -648,11 +136,79 @@ import{randomInt as U}from"node:crypto";import{spawn as Y}from"node:child_proces
|
|
|
648
136
|
.slice(0, 10)
|
|
649
137
|
.map(a => ({ title: a.innerText?.trim() || a.href, url: a.href }));
|
|
650
138
|
return JSON.stringify(links);
|
|
651
|
-
})()`
|
|
652
|
-
|
|
139
|
+
})()`
|
|
140
|
+
], 3000).catch(() => "[]");
|
|
141
|
+
let sources = [];
|
|
142
|
+
try {
|
|
143
|
+
sources = JSON.parse(sourcesExtract || "[]");
|
|
144
|
+
} catch {}
|
|
145
|
+
return { answer, sources };
|
|
146
|
+
}
|
|
147
|
+
} catch {}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
async function extractAnswer(tab, env) {
|
|
151
|
+
const copyBtnExpr = findCopyButtonJsExpression();
|
|
152
|
+
let answer = await clickCopyAndAwaitClipboard(tab, `(${copyBtnExpr})?.click()`, GLOBAL_VAR, { timeoutMs: 2400, retryClick: 400 });
|
|
153
|
+
env.clipboardEmpty = !answer;
|
|
154
|
+
if (env.query && answer) {
|
|
155
|
+
const queryNorm = env.query.toLowerCase().trim();
|
|
156
|
+
const answerNorm = answer.toLowerCase().trim();
|
|
157
|
+
if (answerNorm === queryNorm || answer.trim().length < Math.max(20, queryNorm.length * 0.5)) {
|
|
158
|
+
console.error(`[perplexity] Clipboard contains query echo or stub (${answer.length} chars), retrying with longer wait...`);
|
|
159
|
+
env.clipboardEmpty = true;
|
|
160
|
+
answer = "";
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!answer) {
|
|
164
|
+
console.error("[perplexity] Clipboard empty — trying DOM fallback...");
|
|
165
|
+
const domResult = await extractAnswerFromDom(tab, env);
|
|
166
|
+
if (domResult) {
|
|
167
|
+
console.error(`[perplexity] DOM fallback succeeded (${env.fallbackUsed})`);
|
|
168
|
+
return domResult;
|
|
169
|
+
}
|
|
170
|
+
throw new Error("Clipboard interceptor returned empty text");
|
|
171
|
+
}
|
|
172
|
+
const sources = parseSourcesFromMarkdown(answer);
|
|
173
|
+
return { answer: answer.trim(), sources };
|
|
174
|
+
}
|
|
175
|
+
const USAGE = `Usage: node extractors/perplexity.mjs "<query>" [--tab <prefix>]
|
|
176
|
+
`;
|
|
177
|
+
async function main() {
|
|
178
|
+
const args = await prepareArgs(process.argv.slice(2));
|
|
179
|
+
validateQuery(args, USAGE);
|
|
180
|
+
const { query, tabPrefix, short } = parseArgs(args);
|
|
181
|
+
const startTime = Date.now();
|
|
182
|
+
const mode = process.env.GREEDY_SEARCH_VISIBLE === "1" ? "visible" : "headless";
|
|
183
|
+
const env = {
|
|
184
|
+
engine: "perplexity",
|
|
185
|
+
mode,
|
|
186
|
+
clipboardEmpty: null,
|
|
187
|
+
fallbackUsed: null,
|
|
188
|
+
blockedBy: null,
|
|
189
|
+
verificationResult: null,
|
|
190
|
+
inputReady: null,
|
|
191
|
+
query
|
|
192
|
+
};
|
|
193
|
+
try {
|
|
194
|
+
if (!tabPrefix)
|
|
195
|
+
await cdp(["list"]);
|
|
196
|
+
const tab = await getOrOpenTab(tabPrefix);
|
|
197
|
+
const currentUrl = await cdp(["eval", tab, "document.location.href"]).catch(() => "");
|
|
198
|
+
let onPerplexity = false;
|
|
199
|
+
try {
|
|
200
|
+
const host = new URL(currentUrl).hostname.toLowerCase();
|
|
201
|
+
onPerplexity = host === "perplexity.ai" || host.endsWith(".perplexity.ai");
|
|
202
|
+
} catch {}
|
|
203
|
+
if (!onPerplexity) {
|
|
204
|
+
await cdp(["nav", tab, "https://www.perplexity.ai/"], 20000);
|
|
205
|
+
const _inputReady = await cdp([
|
|
206
|
+
"eval",
|
|
207
|
+
tab,
|
|
208
|
+
`new Promise((resolve) => {
|
|
653
209
|
const _deadline = Date.now() + 15000;
|
|
654
210
|
function _check() {
|
|
655
|
-
const input = document.querySelector('${
|
|
211
|
+
const input = document.querySelector('${S.input}');
|
|
656
212
|
if (input) {
|
|
657
213
|
// Force visibility on all parents up to body —
|
|
658
214
|
// Perplexity hides the first 5 wrapper DIVs until
|
|
@@ -671,8 +227,17 @@ import{randomInt as U}from"node:crypto";import{spawn as Y}from"node:child_proces
|
|
|
671
227
|
else resolve('timeout');
|
|
672
228
|
}
|
|
673
229
|
_check();
|
|
674
|
-
})`
|
|
675
|
-
|
|
230
|
+
})`
|
|
231
|
+
], 18000).catch(() => "timeout");
|
|
232
|
+
if (_inputReady !== "ready") {
|
|
233
|
+
for (let retry = 0;retry < 2; retry++) {
|
|
234
|
+
await cdp(["nav", tab, "https://www.perplexity.ai/"], 20000);
|
|
235
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
236
|
+
const _retryReady = await cdp([
|
|
237
|
+
"eval",
|
|
238
|
+
tab,
|
|
239
|
+
`(() => {
|
|
240
|
+
const input = document.querySelector('${S.input}');
|
|
676
241
|
if (!input) return false;
|
|
677
242
|
let el = input;
|
|
678
243
|
while (el && el !== document.body) {
|
|
@@ -683,9 +248,56 @@ import{randomInt as U}from"node:crypto";import{spawn as Y}from"node:child_proces
|
|
|
683
248
|
}
|
|
684
249
|
input.focus();
|
|
685
250
|
return document.activeElement === input;
|
|
686
|
-
})()`
|
|
251
|
+
})()`
|
|
252
|
+
], 5000).catch(() => false);
|
|
253
|
+
if (_retryReady === "true")
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
await new Promise((r) => setTimeout(r, 600));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const verifyResult = await handleVerification(tab, cdp, 1e4);
|
|
261
|
+
env.verificationResult = verifyResult;
|
|
262
|
+
if (verifyResult === "needs-human") {
|
|
263
|
+
throw new Error("Perplexity verification required — please solve it manually in the browser window");
|
|
264
|
+
}
|
|
265
|
+
await dismissConsent(tab, cdp);
|
|
266
|
+
if (verifyResult === "clicked") {
|
|
267
|
+
await new Promise((r) => setTimeout(r, TIMING.afterVerify));
|
|
268
|
+
const postVerifyUrl = await cdp([
|
|
269
|
+
"eval",
|
|
270
|
+
tab,
|
|
271
|
+
"document.location.href"
|
|
272
|
+
]).catch(() => "");
|
|
273
|
+
let onPerplexityAfter = false;
|
|
274
|
+
try {
|
|
275
|
+
const host = new URL(postVerifyUrl).hostname.toLowerCase();
|
|
276
|
+
onPerplexityAfter = host === "perplexity.ai" || host.endsWith(".perplexity.ai");
|
|
277
|
+
} catch {}
|
|
278
|
+
if (!onPerplexityAfter) {
|
|
279
|
+
await cdp(["nav", tab, "https://www.perplexity.ai/"], 20000);
|
|
280
|
+
await new Promise((r) => setTimeout(r, 800));
|
|
281
|
+
await dismissConsent(tab, cdp);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const inputReady = await waitForSelector(tab, S.input, 15000, 400);
|
|
285
|
+
env.inputReady = inputReady;
|
|
286
|
+
if (!inputReady) {
|
|
287
|
+
throw new Error("Perplexity input not found — page may not have loaded or is in unexpected state");
|
|
288
|
+
}
|
|
289
|
+
await new Promise((r) => setTimeout(r, jitter(300)));
|
|
290
|
+
await injectClipboardInterceptor(tab, GLOBAL_VAR);
|
|
291
|
+
await cdp(["click", tab, S.input]);
|
|
292
|
+
await new Promise((r) => setTimeout(r, jitter(400)));
|
|
293
|
+
let typeResult;
|
|
294
|
+
for (let attempt = 0;attempt < 3; attempt++) {
|
|
295
|
+
typeResult = await cdp([
|
|
296
|
+
"eval",
|
|
297
|
+
tab,
|
|
298
|
+
`(() => {
|
|
687
299
|
try {
|
|
688
|
-
const input = document.querySelector('${
|
|
300
|
+
const input = document.querySelector('${S.input}');
|
|
689
301
|
if (!input) return 'no-input';
|
|
690
302
|
input.focus();
|
|
691
303
|
if (document.activeElement !== input) {
|
|
@@ -695,14 +307,64 @@ import{randomInt as U}from"node:crypto";import{spawn as Y}from"node:child_proces
|
|
|
695
307
|
}
|
|
696
308
|
// execCommand('insertText') dispatches the proper input
|
|
697
309
|
// event that React's onChange listens for
|
|
698
|
-
const ok = document.execCommand('insertText', false, ${JSON.stringify(
|
|
310
|
+
const ok = document.execCommand('insertText', false, ${JSON.stringify(query)});
|
|
699
311
|
return ok ? 'ok' : 'exec-failed';
|
|
700
312
|
} catch (e) { return 'err:' + e.message; }
|
|
701
|
-
})()`
|
|
702
|
-
|
|
313
|
+
})()`
|
|
314
|
+
], 5000);
|
|
315
|
+
if (typeResult === "ok")
|
|
316
|
+
break;
|
|
317
|
+
if (String(typeResult).startsWith("not-focused")) {
|
|
318
|
+
await cdp(["click", tab, S.input]).catch(() => {});
|
|
319
|
+
}
|
|
320
|
+
await new Promise((r) => setTimeout(r, 800));
|
|
321
|
+
}
|
|
322
|
+
if (typeResult !== "ok") {
|
|
323
|
+
throw new Error(`Perplexity type failed: ${typeResult}`);
|
|
324
|
+
}
|
|
325
|
+
await new Promise((r) => setTimeout(r, jitter(400)));
|
|
326
|
+
await cdp([
|
|
327
|
+
"eval",
|
|
328
|
+
tab,
|
|
329
|
+
`(() => {
|
|
330
|
+
const input = document.querySelector('${S.input}');
|
|
703
331
|
if (!input) return 'no-input';
|
|
704
332
|
input.focus();
|
|
705
333
|
const ev = new KeyboardEvent('keydown', { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true, cancelable: true });
|
|
706
334
|
input.dispatchEvent(ev);
|
|
707
335
|
return 'ok';
|
|
708
|
-
})()`
|
|
336
|
+
})()`
|
|
337
|
+
]);
|
|
338
|
+
await waitForStreamComplete(tab, {
|
|
339
|
+
timeout: 20000,
|
|
340
|
+
interval: 600,
|
|
341
|
+
stableRounds: 5,
|
|
342
|
+
minLength: 50,
|
|
343
|
+
selector: `Array.from(document.querySelectorAll('.prose, [class*="prose"]')).pop() || document.querySelector('[data-testid*="answer"], [class*="answer-content"], [class*="response-content"]') || document.body`
|
|
344
|
+
});
|
|
345
|
+
if (process.env.GREEDY_SEARCH_HEADLESS === "1") {
|
|
346
|
+
const postSnap = await cdp(["snap", tab]).catch(() => "");
|
|
347
|
+
if (/\[dialog\]/i.test(postSnap) && /Pro|αναβάθμιση|upgrade/i.test(postSnap) && !/\.prose|\[article\]/i.test(postSnap)) {
|
|
348
|
+
console.error("[perplexity] Rate Limited — skipping (visible retry won't help)");
|
|
349
|
+
env.blockedBy = "rate-limit";
|
|
350
|
+
throw new Error("Rate Limited — Perplexity free search limit reached. Wait a few hours.");
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const { answer, sources } = await extractAnswer(tab, env);
|
|
354
|
+
if (!answer)
|
|
355
|
+
throw new Error("No answer extracted — Perplexity may not have responded");
|
|
356
|
+
const finalUrl = await cdp(["eval", tab, "document.location.href"]).catch(() => "");
|
|
357
|
+
env.durationMs = Date.now() - startTime;
|
|
358
|
+
outputJson({
|
|
359
|
+
query,
|
|
360
|
+
url: finalUrl,
|
|
361
|
+
answer: formatAnswer(answer, short),
|
|
362
|
+
sources,
|
|
363
|
+
_envelope: buildEnvelope(env)
|
|
364
|
+
});
|
|
365
|
+
} catch (e) {
|
|
366
|
+
env.durationMs = Date.now() - startTime;
|
|
367
|
+
handleError(e, buildEnvelope(env));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
main();
|