Subversion Repositories SmartDukaan

Rev

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

Rev 37425 Rev 37428
Line 226... Line 226...
226
    /** Stash the getDeviceInfo response on window as the page receives it. */
226
    /** Stash the getDeviceInfo response on window as the page receives it. */
227
    private void installResponseCapture(WebDriver driver) {
227
    private void installResponseCapture(WebDriver driver) {
228
        try {
228
        try {
229
            ((JavascriptExecutor) driver).executeScript(
229
            ((JavascriptExecutor) driver).executeScript(
230
                "if (!window.__oppoCapInstalled) {"
230
                "if (!window.__oppoCapInstalled) {"
231
              + "  window.__oppoCapInstalled = true; window.__oppoResp = null;"
231
              + "  window.__oppoCapInstalled = true; window.__oppoResp = null; window.__oppoCaptcha = null;"
232
              // axios can sit on either transport, and realme's page uses fetch --
232
              // axios can sit on either transport, and realme's page uses fetch --
233
              // an XHR-only hook silently captures nothing, which is exactly what
233
              // an XHR-only hook silently captures nothing, which is exactly what
234
              // 'no getDeviceInfo response captured' was reporting.
234
              // 'no getDeviceInfo response captured' was reporting.
235
              + "  var O = XMLHttpRequest.prototype.open;"
235
              + "  var O = XMLHttpRequest.prototype.open;"
236
              + "  XMLHttpRequest.prototype.open = function(m,u){"
236
              + "  XMLHttpRequest.prototype.open = function(m,u){"
237
              + "    this.addEventListener('load', function(){"
237
              + "    this.addEventListener('load', function(){"
-
 
238
              + "      try { var s=String(u);"
238
              + "      try { if (String(u).indexOf('getDeviceInfo') !== -1) window.__oppoResp = this.responseText; } catch(e){}"
239
              + "        if (s.indexOf('getDeviceInfo') !== -1) window.__oppoResp = this.responseText;"
-
 
240
              + "        else if (s.indexOf('captcha') !== -1) window.__oppoCaptcha = s + ' -> ' + (this.responseText||'').slice(0,200);"
-
 
241
              + "      } catch(e){}"
239
              + "    });"
242
              + "    });"
240
              + "    return O.apply(this, arguments);"
243
              + "    return O.apply(this, arguments);"
241
              + "  };"
244
              + "  };"
242
              + "  var F = window.fetch;"
245
              + "  var F = window.fetch;"
243
              + "  if (F) { window.fetch = function(){"
246
              + "  if (F) { window.fetch = function(){"
Line 251... Line 254...
251
        } catch (Exception e) {
254
        } catch (Exception e) {
252
            LOGGER.warn("Could not install the response capture hook: " + e.getMessage());
255
            LOGGER.warn("Could not install the response capture hook: " + e.getMessage());
253
        }
256
        }
254
    }
257
    }
255
 
258
 
-
 
259
    /** Last response from the captcha widget itself -- says WHY a drag was refused. */
-
 
260
    private String captchaSignal(WebDriver driver) {
-
 
261
        try {
-
 
262
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__oppoCaptcha || null;");
-
 
263
            return v == null ? null : v.toString();
-
 
264
        } catch (Exception e) {
-
 
265
            return null;
-
 
266
        }
-
 
267
    }
-
 
268
 
256
    private String capturedResponse(WebDriver driver) {
269
    private String capturedResponse(WebDriver driver) {
257
        try {
270
        try {
258
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__oppoResp || null;");
271
            Object v = ((JavascriptExecutor) driver).executeScript("return window.__oppoResp || null;");
259
            return v == null ? null : v.toString();
272
            return v == null ? null : v.toString();
260
        } catch (Exception e) {
273
        } catch (Exception e) {