Subversion Repositories SmartDukaan

Rev

Rev 37433 | Rev 37435 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37433 Rev 37434
Line 238... Line 238...
238
    private void installResponseCapture(WebDriver driver) {
238
    private void installResponseCapture(WebDriver driver) {
239
        try {
239
        try {
240
            ((JavascriptExecutor) driver).executeScript(
240
            ((JavascriptExecutor) driver).executeScript(
241
                "if (!window.__oppoCapInstalled) {"
241
                "if (!window.__oppoCapInstalled) {"
242
              + "  window.__oppoCapInstalled = true; window.__oppoResp = null; window.__oppoCaptcha = null;"
242
              + "  window.__oppoCapInstalled = true; window.__oppoResp = null; window.__oppoCaptcha = null;"
-
 
243
              // __oppoCaptcha is last-captcha-call-wins, and the widget refetches a puzzle
-
 
244
              // (/api/a) straight after a rejected verify (/api/v1). We then wait up to 5s
-
 
245
              // for the error element before reading it, which is ample time for the
-
 
246
              // refetch to overwrite the verdict -- so "all failures show /api/a" cannot
-
 
247
              // distinguish "never verified" from "verified, rejected, then overwritten".
-
 
248
              // Keep the verify separately, and a count, so the two are distinguishable.
-
 
249
              + "  window.__oppoVerify = null; window.__oppoVerifyCount = 0;"
243
              // axios can sit on either transport, and realme's page uses fetch --
250
              // axios can sit on either transport, and realme's page uses fetch --
244
              // an XHR-only hook silently captures nothing, which is exactly what
251
              // an XHR-only hook silently captures nothing, which is exactly what
245
              // 'no getDeviceInfo response captured' was reporting.
252
              // 'no getDeviceInfo response captured' was reporting.
246
              + "  var O = XMLHttpRequest.prototype.open;"
253
              + "  var O = XMLHttpRequest.prototype.open;"
247
              + "  XMLHttpRequest.prototype.open = function(m,u){"
254
              + "  XMLHttpRequest.prototype.open = function(m,u){"
248
              + "    this.addEventListener('load', function(){"
255
              + "    this.addEventListener('load', function(){"
249
              + "      try { var s=String(u);"
256
              + "      try { var s=String(u);"
250
              + "        if (s.indexOf('getDeviceInfo') !== -1) window.__oppoResp = this.responseText;"
257
              + "        if (s.indexOf('getDeviceInfo') !== -1) window.__oppoResp = this.responseText;"
-
 
258
              + "        else if (s.indexOf('/api/v1') !== -1) { window.__oppoVerifyCount++; window.__oppoVerify = (this.responseText||'').slice(0,160); window.__oppoCaptcha = s + ' -> ' + (this.responseText||'').slice(0,200); }"
251
              + "        else if (s.indexOf('captcha') !== -1) window.__oppoCaptcha = s + ' -> ' + (this.responseText||'').slice(0,200);"
259
              + "        else if (s.indexOf('captcha') !== -1) window.__oppoCaptcha = s + ' -> ' + (this.responseText||'').slice(0,200);"
252
              + "      } catch(e){}"
260
              + "      } catch(e){}"
253
              + "    });"
261
              + "    });"
254
              + "    return O.apply(this, arguments);"
262
              + "    return O.apply(this, arguments);"
255
              + "  };"
263
              + "  };"
Line 286... Line 294...
286
    }
294
    }
287
 
295
 
288
    /** Last response from the captcha widget itself -- says WHY a drag was refused. */
296
    /** Last response from the captcha widget itself -- says WHY a drag was refused. */
289
    private String captchaSignal(WebDriver driver) {
297
    private String captchaSignal(WebDriver driver) {
290
        try {
298
        try {
291
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__oppoCaptcha || null;");
299
            Object v = ((JavascriptExecutor) driver).executeScript(
-
 
300
                    "return 'verifies=' + (window.__oppoVerifyCount||0)"
-
 
301
                  + " + ' lastVerify=' + (window.__oppoVerify || 'NONE')"
-
 
302
                  + " + ' | ' + (window.__oppoCaptcha || 'none');");
292
            return v == null ? null : v.toString();
303
            return v == null ? null : v.toString();
293
        } catch (Exception e) {
304
        } catch (Exception e) {
294
            return null;
305
            return null;
295
        }
306
        }
296
    }
307
    }