1

I'm using this code in chrome and firefox console

let m=$.getScript("https://html2canvas.hertzen.com/dist/html2canvas.js", function() {
html2canvas(document.querySelector("body > table.troisbords > tbody > tr > td > table > tbody > tr > td > div > blockquote > table > tbody > tr:nth-child(2) > td > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > img"), {
            onrendered: function(canvas) {
                 var myImage = canvas.toDataURL("image/png");
        return myImage;
               },
                       allowTaint: true,
                    taintTest: false
         });
         }); 


m.then((value) => {
    console.log(value);
    window.open(value);
});

but i'm getting the following

please check the image

I've checked these answers:

Why is my asynchronous function returning Promise { <pending> } instead of a value?

Appreciate any help !

Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
user11845248
  • 131
  • 8
  • The complete callback is not part of the promise chain. Consider just passing a function reference to `onrendered` and consume the url there – charlietfl Jul 28 '19 at 00:44
  • You have nowhere to `return` to in `onrendered`. Could also just call a function that has the url as argument – charlietfl Jul 28 '19 at 00:48
  • @charlietfl can you please provide an edited code ? – user11845248 Jul 28 '19 at 00:49
  • @charlietfl i don't have big knowledge in js, i will inject the code in android webview i tried for many hours but nothing worked, i just want to get the data url of the current shown captcha, the only code works, gives me another captcha – user11845248 Jul 28 '19 at 00:54

1 Answers1

-1

You could just pass a function reference to onrendered and do whatever you need to with the resultant url there

function onCanvasRender(canvas) {
  var myImage = canvas.toDataURL("image/png");
  console.log(myImage);
}


$.getScript("https://html2canvas.hertzen.com/dist/html2canvas.js", function() {
  html2canvas(document.querySelector("body > table.troisbords > tbody > tr > td > table > tbody > tr > td > div > blockquote > table > tbody > tr:nth-child(2) > td > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > img"), {
    onrendered: onCanvasRender,
    allowTaint: true,
    taintTest: false
  });
});
charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • Thank you, but i'm getting `{readyState: 1, setRequestHeader: ƒ, getAllResponseHeaders: ƒ, getResponseHeader: ƒ, overrideMimeType: ƒ, …}` in chrome and firefox console, i use them to test the script in the website before i put it in my android app – user11845248 Jul 28 '19 at 01:03
  • That's the xhr object. Not sure how you ever got that – charlietfl Jul 28 '19 at 01:07
  • did you test it in your side in chrome or firefox ? this is the website https://www4.inscription.tn/ORegMx/servlet/AuthentificationEtud?ident=cin – user11845248 Jul 28 '19 at 01:11
  • That's a jqXHR object, not an XHR object and it's the return value of `$.getScript()` – MinusFour Jul 28 '19 at 01:28
  • @MinusFour so what to change in the code in order to get the right captcha data url ? – user11845248 Jul 28 '19 at 01:44