title: I am unable to get data from javaScript in Flutter
body: <p>I am try to inject some javascript code to get some value in flutter with webview_flutter some of the data I am able  to get but when I use try catch or function its not working with an error</p>
  <blockquote>
  <p>[INFO:CONSOLE(1)] &quot;Uncaught SyntaxError: Unexpected token 'var'&quot;, source: <a href="https://rads.stackoverflow.com/amzn/click/com/B07TPPZYFV" rel="nofollow noreferrer" rel="nofollow noreferrer">https://www.amazon.com/Hanes-Heavyweight-Henley-Slate-Heather/dp/B07TPPZYFV/</a> (1)</p>
  </blockquote>
  <pre><code>import 'dart:async';
  import 'package:flutter/material.dart';
  import 'package:webview_flutter/webview_flutter.dart';
  </code></pre>
  <p>The stateful widget with webview</p>
  <pre><code>    class JSInWebView extends StatefulWidget {
        @override
        JSInWebViewState createState() {
          return new JSInWebViewState();
        }
      }
      
      class JSInWebViewState extends State&lt;JSInWebView&gt; {
        // final flutterWebviewPlugin = new FlutterWebviewPlugin();
      
        final Completer &lt;WebViewController&gt; _controller = Completer&lt;WebViewController&gt;();
      
      
      // var productTitle;
      var js = 'document.querySelector(&quot;#partialStateBuybox&quot;).remove()';
      
     
        @override
        void initState(){
          super.initState();
        }
      
        @override
        void dispose() {
          super.dispose();
        }
  </code></pre>
  <p>The widget for loading the webView and run the javaScript code</p>
  <pre><code>@override
        Widget build(BuildContext context) {
          return Scaffold(
            body:WebView(
              javascriptMode: JavascriptMode.unrestricted,
              initialUrl: 'https://www.amazon.com/Hanes-Heavyweight-Henley-Slate-Heather/dp/B07TPPZYFV/',
              onWebViewCreated: (WebViewController webViewController){
                _controller.complete(webViewController);
              },
              onPageFinished: (url){
                allJsfile();
              },
              javascriptChannels: &lt;JavascriptChannel&gt;[
                _getPInfoChannel(),
                _getPColor(context),
              ].toSet(),
            ),
      
            floatingActionButton: _showUrlbtn(),
          );
        }
      
        Widget _showUrlbtn(){
          return FutureBuilder&lt;WebViewController&gt;(
              future: _controller.future,
            builder: (BuildContext context, AsyncSnapshot&lt;WebViewController&gt; controller){
      
                if(controller.hasData){
                  return FloatingActionButton(
                    child: Icon(Icons.link),
                    onPressed: () async{
                      String ss = await controller.data.currentUrl();
                      print(ss);
                    },
                  );
                }else{
                  return Container();
                }
            },
          );
      
        }
      
       void allJsfile() {
      
  // var localjs = 'let color = () =&gt; {try {productColor = document.getElementById(&quot;color_name-button&quot;).innerText.trim().split(&quot;:&quot;)[1].trim()} catch {productColor = &quot;&quot;;try {let bulkArray = document.getElementById(&quot;inline-twister-experiment-container&quot;).innerText.trim().split(&quot;\\n&quot;);for (let i = 0; i &lt; bulkArray.length; i++) {if (bulkArray[i].includes(&quot;Color&quot;)) {productColor = bulkArray[i].split(&quot;:&quot;)[1].trim();}}} catch {productColor = &quot;&quot;;}} return productColor;};';
  
      _controller.future.then((value) {
            value.evaluateJavascript(js);
            value.evaluateJavascript('productitle.postMessage(document.getElementById(&quot;title&quot;).innerText.trim());');
            // value.evaluateJavascript(&quot;producColor.postMessage(let bulkArray = document.getElementById('inline-twister-experiment-container').innerText.trim().split('\\n');for(let i = 0; i &lt; bulkArray.length; i++) {if (bulkArray[i].includes('Color')) {productColor = bulkArray[i].split(':')[1].trim();}})&quot;);
            value.evaluateJavascript('color.postMessage(var productPrice=()=&gt;{let e=document.getElementById(&quot;priceblock_ourprice&quot;);if(null!=e&amp;&amp;&quot;&quot;!=e&amp;&amp;null!=e)return e.innerText.trim();{let r=document.getElementById(&quot;newPitchPriceWrapper_feature_div&quot;).innerText.trim().split(&quot; &quot;);if(null!=(e=r[0]+r[1]+&quot;.&quot;+r[2])&amp;&amp;&quot;&quot;!=e)return console.log(e),e}return&quot;&quot;};productPrice(););');
      
      
          });
        }
      
        JavascriptChannel _getPInfoChannel() {
          return JavascriptChannel(
              name: 'productitle',
              onMessageReceived: (JavascriptMessage message){
                String ssss = message.message;
                print(&quot;Title: $ssss&quot;);
          });
        }
        JavascriptChannel _getPColor(BuildContext context) {
          
          return JavascriptChannel(
              name: 'color',
              onMessageReceived: (message){
                String ssss = message.message;
      
      
                print(&quot;Color: &quot;+ message.message);
          });
        }
      }
  </code></pre>