ask-web-fetch 0.7.7 → 0.8.1
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.
- checksums.yaml +4 -4
- data/lib/ask/web_fetch/backends/browser.rb +46 -5
- data/lib/ask/web_fetch/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4eee949761f2fc7f62b8104f6758697325505c748e8e05890c8082763edbba78
|
|
4
|
+
data.tar.gz: 716a358c4b95ec5718567ef4d021936166f03d8b429b334e36d443e5684cb440
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3c64fbf2c920510119ffd4840a5477b0dbe829e76162ff6fb9f83722407b4716b794a71a8dd80a2609c7323c6482922e6f8570c7817ce9c090d2850eeb9f258
|
|
7
|
+
data.tar.gz: 1b779236529f3f0523af90c4ec0e4216e7303c7270e135864f0826943b7a4e4ed7ac74fca022c28b171870c881aa31887b6a5d03dbf67584d1f5d9c2cdaa765f
|
|
@@ -54,6 +54,18 @@ module Ask
|
|
|
54
54
|
# How often to poll for the challenge to clear.
|
|
55
55
|
POLL_INTERVAL = 0.5
|
|
56
56
|
|
|
57
|
+
# Brave paths — Brave's fingerprinting resistance (canvas, WebGL,
|
|
58
|
+
# audio randomization) helps against Cloudflare/DataDome, but
|
|
59
|
+
# benchmarks show Chrome renders SPAs (reddit) more reliably.
|
|
60
|
+
# Chrome is preferred; Brave is the fallback. Override either
|
|
61
|
+
# with ASK_WEB_FETCH_BROWSER_PATH.
|
|
62
|
+
BRAVE_PATHS = [
|
|
63
|
+
'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
|
|
64
|
+
'/usr/bin/brave-browser',
|
|
65
|
+
'/usr/bin/brave-browser-stable',
|
|
66
|
+
'/opt/brave.com/brave/brave-browser'
|
|
67
|
+
].freeze
|
|
68
|
+
|
|
57
69
|
DEFAULT_PATHS = [
|
|
58
70
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
59
71
|
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
@@ -64,6 +76,11 @@ module Ask
|
|
|
64
76
|
'/opt/google/chrome/chrome'
|
|
65
77
|
].freeze
|
|
66
78
|
|
|
79
|
+
# Random viewport dimensions (FHD to 2K) — a fixed window size is
|
|
80
|
+
# a fingerprinting signal. Each fetch gets a fresh random size.
|
|
81
|
+
VIEWPORT_WIDTH_RANGE = (1920..2560).freeze
|
|
82
|
+
VIEWPORT_HEIGHT_RANGE = (1080..1440).freeze
|
|
83
|
+
|
|
67
84
|
class << self
|
|
68
85
|
# The shared browser (or a test double). Reuse keeps the solved
|
|
69
86
|
# challenge cookie warm across fetches within one process.
|
|
@@ -72,14 +89,17 @@ module Ask
|
|
|
72
89
|
# The ContentFilter applied to every page by default.
|
|
73
90
|
attr_writer :content_filter
|
|
74
91
|
|
|
75
|
-
# Absolute path to a Chrome/Chromium binary; nil when not found.
|
|
92
|
+
# Absolute path to a Chrome/Chromium/Brave binary; nil when not found.
|
|
93
|
+
# Prefers Brave (fingerprinting resistance) over Chrome/Chromium.
|
|
94
|
+
# Override with ASK_WEB_FETCH_BROWSER_PATH (any Chromium-based
|
|
95
|
+
# browser) or the legacy ASK_WEB_FETCH_CHROME_PATH.
|
|
76
96
|
attr_writer :path
|
|
77
97
|
|
|
78
|
-
# CDP endpoint of an already-running
|
|
98
|
+
# CDP endpoint of an already-running browser ("http://host:port",
|
|
79
99
|
# "…/json/version", or a ws:// browser URL) to attach to instead.
|
|
80
100
|
attr_writer :cdp_url
|
|
81
101
|
|
|
82
|
-
attr_writer :challenge_timeout, :poll_interval
|
|
102
|
+
attr_writer :challenge_timeout, :poll_interval, :viewport
|
|
83
103
|
|
|
84
104
|
# Domains already given a warm pass this process — a failed warm
|
|
85
105
|
# (DataDome-class wall) is not re-paid at CHALLENGE_TIMEOUT on
|
|
@@ -107,7 +127,26 @@ module Ask
|
|
|
107
127
|
end
|
|
108
128
|
|
|
109
129
|
def path
|
|
110
|
-
@path || ENV['
|
|
130
|
+
@path || ENV['ASK_WEB_FETCH_BROWSER_PATH'] || ENV['ASK_WEB_FETCH_CHROME_PATH'] ||
|
|
131
|
+
DEFAULT_PATHS.find { |p| File.exist?(p) } ||
|
|
132
|
+
BRAVE_PATHS.find { |p| File.exist?(p) }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# A fresh random viewport for each browser launch — a fixed
|
|
136
|
+
# window size is a fingerprinting signal. Returns { width:,
|
|
137
|
+
# height: } in the FHD-to-2K range. Override with
|
|
138
|
+
# Browser.viewport = { width: 1920, height: 1080 } for tests.
|
|
139
|
+
def viewport
|
|
140
|
+
@viewport || {
|
|
141
|
+
width: rand(VIEWPORT_WIDTH_RANGE),
|
|
142
|
+
height: rand(VIEWPORT_HEIGHT_RANGE)
|
|
143
|
+
}
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# True when the configured binary is Brave (fingerprinting-
|
|
147
|
+
# resistant) rather than stock Chrome/Chromium.
|
|
148
|
+
def brave?
|
|
149
|
+
path.to_s.match?(/brave/i)
|
|
111
150
|
end
|
|
112
151
|
|
|
113
152
|
def cdp_url
|
|
@@ -152,11 +191,13 @@ module Ask
|
|
|
152
191
|
def build_browser
|
|
153
192
|
return AttachedBrowser.new(ws_url_for(cdp_url), timeout: CHALLENGE_TIMEOUT + IDLE_TIMEOUT) if cdp_url
|
|
154
193
|
|
|
194
|
+
vp = viewport
|
|
155
195
|
Ferrum::Browser.new(
|
|
156
196
|
browser_path: path,
|
|
157
197
|
headless: true,
|
|
158
198
|
user_data_dir: ENV['ASK_WEB_FETCH_PROFILE'],
|
|
159
|
-
timeout: CHALLENGE_TIMEOUT + IDLE_TIMEOUT
|
|
199
|
+
timeout: CHALLENGE_TIMEOUT + IDLE_TIMEOUT,
|
|
200
|
+
window_size: [vp[:width], vp[:height]]
|
|
160
201
|
)
|
|
161
202
|
end
|
|
162
203
|
end
|