Skip to content

evalJavascript(document.documentElement.innerHTML) escaped text? #417

@AnsonLai

Description

@AnsonLai

I'm trying to get the source from a webview, and I'm using evalJavascript to try and get the document's innerHTML:

@override void initState() { flutterWebviewPlugin.onStateChanged.listen((state) async { if (state.type == WebViewState.finishLoad) { String response = await flutterWebviewPlugin.evalJavascript('document.documentElement.innerHTML;'); print(response); } }); }

But the output is always some form of escaped text:
"\u003Chead>\u003Cmeta charset=\"UTF-8\">\u003Cmeta content=\"width=device-width,minimum-scale=1.0\" name=\"viewport\">\u003Cmeta content=\"telephone=no\" name=\"format-detection\">\u003Cmeta content=\"address=no\" name=\"format-detection\">\u003Cmeta content=\"origin\" name=\"referrer\">\u003Cmeta content=\"notranslate\" name=\"google\">\u003Clink href=\"/images/branding/product/1x/gsa_android_144dp.png\" rel=\"icon\">\u003Cmeta content=\"/images/branding/googleg/1x/googleg_standard_color_128dp.png\" itemprop=\"image\">

Is this the proper behavior? I can't seem to figure out what type of escape this is. One of the things I was thinking is if there was a way to catch it earlier? I noticed that if I use console.log, it seems to output in the flutter console in proper formatting:

String response = await flutterWebviewPlugin.evalJavascript('console.log(document.documentElement.innerHTML);');

Which yields something like this:

[INFO:CONSOLE(1)] "<head><meta charset="UTF-8"><meta content="width=device-width,minimum-scale=1.0" name="viewport"><meta content="telephone=no" name="format-detection"><meta content="address=no" name="format-detection"><meta content="origin" name="referrer"><meta content="notranslate" name="google"><link href="/images/branding/product/1x/gsa_android_144dp.png" rel="icon"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="vnS8R6Yzt54tLKduMnYLPg==">

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions