Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evalJavascript() won't work HTML DOM Methods #304

Closed
rma6 opened this issue Jan 23, 2019 · 3 comments
Closed

evalJavascript() won't work HTML DOM Methods #304

rma6 opened this issue Jan 23, 2019 · 3 comments

Comments

@rma6
Copy link

rma6 commented Jan 23, 2019

I'm trying to a input with text and submit a form.
When I press a button the following function is called

Future<void> _handleCNPJ() async {
    FlutterWebviewPlugin webView = new FlutterWebviewPlugin();

    await webView.launch(
      'http://www.receita.fazenda.gov.br/PessoaJuridica/CNPJ/cnpjreva/Cnpjreva_Solicitacao.asp',
      rect: new Rect.fromLTWH(0.0, 0.0, MediaQuery.of(context).size.width,
          MediaQuery.of(context).size.height / 2),
      userAgent: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, 
          like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36',
      scrollBar: false,
      withZoom: false,
      supportMultipleWindows: false,
    );
    
    await webView.evalJavascript("document.getElementById('cnpj').value = 'testing'");
    await webView.close();
  }

But nothing happens on the WebView.
What am I doing wrong?

Thanks in advance.

@rma6
Copy link
Author

rma6 commented Jan 25, 2019

I've found out that I wasn't waiting long enough to run the JS.

@rma6 rma6 closed this as completed Jan 25, 2019
@erdemyerebasmaz
Copy link

erdemyerebasmaz commented Jan 27, 2019

@rma6
I don't know how you solved this but you can listen to state changes.
e.g.;

webView.onStateChanged.listen((state) async {
    if (state.type == WebViewState.finishLoad) {
        webView.evalJavascript("document.getElementById('cnpj').value = 'testing'");
    }
});

@rma6
Copy link
Author

rma6 commented Jan 28, 2019

That's exactly what I did. Actualy I tried this approach first, but it wasn't working because I was initializing the listener in the wrong place. I had to put this code inside the initState()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants