evgenyneu / js-evaluator-for-android

A library for running JavaScript in Android apps.
MIT License
485 stars 84 forks source link

Null return value using external js library #52

Closed 0xCTF closed 5 years ago

0xCTF commented 5 years ago

Hi, I'm trying to get a screenshot for an element in webview which is a captcha in android

i'm using this code, in onPageFinished

 String jsCode="";
                    jsCode+= loadJs("testjs/html2canvas.js");
                    jsCode += "; ";
                    jsCode += "$(document).ready(function() {\n" +
                            "    html2canvas($(\"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\"), {\n" +
                            "        onrendered: function(canvas) {\n" +
                            "            var myImage = canvas.toDataURL(\"image/png\");\n" +
                            "         }\n" +
                            "    });\n" +
                            "});";

                    view.evaluateJavascript("("+jsCode+"})();",
                            new ValueCallback<String>() {
                                @Override
                                public void onReceiveValue(String html) {
                                    Toast.makeText(Moyenne.this, "yow"+html, Toast.LENGTH_SHORT).show();
                                }
                            });
 protected String ReadFile(String fileName) throws IOException {
        final AssetManager am = getAssets();
        final InputStream inputStream = am.open(fileName);

        Scanner scanner = new Scanner(inputStream, "UTF-8");
        return scanner.useDelimiter("\\A").next();
    }
 private String loadJs(String fileName) {
        try {
            return ReadFile(fileName);
        } catch (final IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

But the value returned is null, it suppose to get data:image/png;base64,... How can i fix that ? this is the website loaded in the webview https://www4.inscription.tn/ORegMx/servlet/AuthentificationEtud?ident=cin

Hope someone can help to get a screenshot of the captcha

evgenyneu commented 5 years ago

Hi, @0xCTF. I can see that you are accessing a web view directly. I think this is not a good place to discuss the usage of a web view. Here we discuss issues related to 'js-evaluator-for-android' library, and not Android programming in general.

As I suggested before, I think it would be best to ask for help on programming forums, like stackoverflow.

0xCTF commented 5 years ago

Alright, sorry for that