| Line 174... |
Line 174... |
| 174 |
//
|
174 |
//
|
| 175 |
// The lookup response arriving is the only signal that actually proves
|
175 |
// The lookup response arriving is the only signal that actually proves
|
| 176 |
// the captcha passed, so wait for that instead.
|
176 |
// the captcha passed, so wait for that instead.
|
| 177 |
String json = awaitResponse(driver, 8000);
|
177 |
String json = awaitResponse(driver, 8000);
|
| 178 |
if (json == null) {
|
178 |
if (json == null) {
|
| 179 |
LOGGER.warn("Failed = {} (captcha said: {})",
|
179 |
LOGGER.warn("Failed = {} (captcha said: {}) urls={}",
|
| 180 |
counter, captchaSignal(driver));
|
180 |
counter, captchaSignal(driver), seenUrls(driver));
|
| 181 |
} else {
|
181 |
} else {
|
| 182 |
LOGGER.info("Success at attempt " + counter);
|
182 |
LOGGER.info("Success at attempt " + counter);
|
| 183 |
//List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
|
183 |
//List<WebElement> warrantyDateElements = driver.findElements(By.className("warranty-service--result_info__dateValue"));
|
| 184 |
//WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5') or contains(text(), 'Non-Activate')]"));
|
184 |
//WebElement activationTimeElement = driver.findElement(By.xpath("//*[contains(text(), 'UTC+5.5') or contains(text(), 'Non-Activate')]"));
|
| 185 |
// Read the JSON the page already received. The old locator
|
185 |
// Read the JSON the page already received. The old locator
|
| Line 273... |
Line 273... |
| 273 |
/** Stash the active/check response on window as the page receives it. */
|
273 |
/** Stash the active/check response on window as the page receives it. */
|
| 274 |
private void installResponseCapture(WebDriver driver) {
|
274 |
private void installResponseCapture(WebDriver driver) {
|
| 275 |
try {
|
275 |
try {
|
| 276 |
((JavascriptExecutor) driver).executeScript(
|
276 |
((JavascriptExecutor) driver).executeScript(
|
| 277 |
"if (!window.__rmCapInstalled) {"
|
277 |
"if (!window.__rmCapInstalled) {"
|
| 278 |
+ " window.__rmCapInstalled = true; window.__rmResp = null; window.__rmCaptcha = null;"
|
278 |
+ " window.__rmCapInstalled = true; window.__rmResp = null; window.__rmCaptcha = null; window.__rmSeen = [];"
|
| 279 |
// axios can sit on either transport, and realme's page uses fetch --
|
279 |
// axios can sit on either transport, and realme's page uses fetch --
|
| 280 |
// an XHR-only hook silently captures nothing, which is exactly what
|
280 |
// an XHR-only hook silently captures nothing, which is exactly what
|
| 281 |
// 'no active/check response captured' was reporting.
|
281 |
// 'no active/check response captured' was reporting.
|
| 282 |
+ " var O = XMLHttpRequest.prototype.open;"
|
282 |
+ " var O = XMLHttpRequest.prototype.open;"
|
| 283 |
+ " XMLHttpRequest.prototype.open = function(m,u){"
|
283 |
+ " XMLHttpRequest.prototype.open = function(m,u){"
|
| 284 |
+ " this.addEventListener('load', function(){"
|
284 |
+ " this.addEventListener('load', function(){"
|
| 285 |
+ " try { var s=String(u);"
|
285 |
+ " try { var s=String(u);"
|
| 286 |
+ " if (s.indexOf('active/check') !== -1) window.__rmResp = this.responseText;"
|
286 |
+ " if (s.indexOf('active/check') !== -1 || s.indexOf('customer-api') !== -1) window.__rmResp = this.responseText;"
|
| 287 |
+ " else if (s.indexOf('captcha') !== -1) window.__rmCaptcha = s + ' -> ' + (this.responseText||'').slice(0,200);"
|
287 |
+ " else if (s.indexOf('captcha') !== -1) window.__rmCaptcha = s + ' -> ' + (this.responseText||'').slice(0,200);"
|
| - |
|
288 |
+ " else if (window.__rmSeen.length < 12) window.__rmSeen.push(s.slice(0,80));"
|
| 288 |
+ " } catch(e){}"
|
289 |
+ " } catch(e){}"
|
| 289 |
+ " });"
|
290 |
+ " });"
|
| 290 |
+ " return O.apply(this, arguments);"
|
291 |
+ " return O.apply(this, arguments);"
|
| 291 |
+ " };"
|
292 |
+ " };"
|
| 292 |
+ " var F = window.fetch;"
|
293 |
+ " var F = window.fetch;"
|
| 293 |
+ " if (F) { window.fetch = function(){"
|
294 |
+ " if (F) { window.fetch = function(){"
|
| 294 |
+ " var u = arguments[0]; u = (u && u.url) ? u.url : String(u);"
|
295 |
+ " var u = arguments[0]; u = (u && u.url) ? u.url : String(u);"
|
| 295 |
+ " return F.apply(this, arguments).then(function(r){"
|
296 |
+ " return F.apply(this, arguments).then(function(r){"
|
| 296 |
+ " try { if (u.indexOf('active/check') !== -1) { r.clone().text().then(function(t){ window.__rmResp = t; }); } } catch(e){}"
|
297 |
+ " try { if (u.indexOf('active/check') !== -1 || u.indexOf('customer-api') !== -1) { r.clone().text().then(function(t){ window.__rmResp = t; }); }"
|
| - |
|
298 |
+ " else if (window.__rmSeen.length < 12) window.__rmSeen.push('F ' + u.slice(0,80)); } catch(e){}"
|
| 297 |
+ " return r;"
|
299 |
+ " return r;"
|
| 298 |
+ " });"
|
300 |
+ " });"
|
| 299 |
+ " }; }"
|
301 |
+ " }; }"
|
| 300 |
+ "}");
|
302 |
+ "}");
|
| 301 |
} catch (Exception e) {
|
303 |
} catch (Exception e) {
|
| Line 331... |
Line 333... |
| 331 |
} catch (Exception e) {
|
333 |
} catch (Exception e) {
|
| 332 |
return null;
|
334 |
return null;
|
| 333 |
}
|
335 |
}
|
| 334 |
}
|
336 |
}
|
| 335 |
|
337 |
|
| - |
|
338 |
/** Non-captcha URLs the page called -- shows what to match on when the lookup is missed. */
|
| - |
|
339 |
private String seenUrls(WebDriver driver) {
|
| - |
|
340 |
try {
|
| - |
|
341 |
Object v = ((JavascriptExecutor) driver).executeScript(
|
| - |
|
342 |
"return (window.__rmSeen||[]).join(' | ');");
|
| - |
|
343 |
return v == null ? "" : v.toString();
|
| - |
|
344 |
} catch (Exception e) {
|
| - |
|
345 |
return "";
|
| - |
|
346 |
}
|
| - |
|
347 |
}
|
| - |
|
348 |
|
| 336 |
private String capturedResponse(WebDriver driver) {
|
349 |
private String capturedResponse(WebDriver driver) {
|
| 337 |
try {
|
350 |
try {
|
| 338 |
Object v = ((JavascriptExecutor) driver).executeScript("return window.__rmResp || null;");
|
351 |
Object v = ((JavascriptExecutor) driver).executeScript("return window.__rmResp || null;");
|
| 339 |
return v == null ? null : v.toString();
|
352 |
return v == null ? null : v.toString();
|
| 340 |
} catch (Exception e) {
|
353 |
} catch (Exception e) {
|