title: how to return javascript function value from webbrowser c#
body: <p>hi Awesomium browser provide JavaScript execute with result method to return values like this :</p>
  
  <pre><code>private const String JS_FAVICON = "(function(){links = document.getElementsByTagName('link'); wHref=window.location.protocol + '//' + window.location.hostname + '/favicon.ico'; for(i=0; i&lt;links.length; i++){s=links[i].rel; if(s.indexOf('icon') != -1){ wHref = links[i].href }; }; return wHref; })();";
  string val = webControl.ExecuteJavascriptWithResult(JS_FAVICON); 
  </code></pre>
  
  <p>however i need to perform this with c# builtin browser how to do it,
  i think there is method "webBrowser1.Document.InvokeScript" not sure how to use it.. </p>
  
  <p>edited...
  this how Awesomium browser return the value:</p>
  
  <pre><code>private void Awesomium_Windows_Forms_WebControl_DocumentReady(object  sender, UrlEventArgs e)
      {
          // DOM is ready. We can start looking for a favicon.
          //UpdateFavicon();
      }
  
  
   private void UpdateFavicon()
      {
          // Execute some simple javascript that will search for a favicon.
          string val = webControl.ExecuteJavascriptWithResult(JS_FAVICON);
  
          // Check for any errors.
          if (webControl.GetLastError() != Error.None)
              return;
  
          // Check if we got a valid response.
          if (String.IsNullOrEmpty(val) || !Uri.IsWellFormedUriString(val, UriKind.Absolute))
              return;
  
          // We do not need to perform the download of the favicon synchronously.
          // May be a full icon set (thus big).
          Task.Factory.StartNew&lt;Icon&gt;(GetFavicon, val).ContinueWith(t =&gt;
          {
              // If the download completed successfully, set the new favicon.
              // This post-completion procedure is executed synchronously.
  
              if (t.Exception != null)
                  return;
  
              if (t.Result != null)
                  this.Icon = t.Result;
  
              if (this.DockPanel != null)
                  this.DockPanel.Refresh();
          },
          TaskScheduler.FromCurrentSynchronizationContext());
      }
  
      private static Icon GetFavicon(Object href)
      {
          using (WebClient client = new WebClient())
          {
              Byte[] data = client.DownloadData(href.ToString());
  
              if ((data == null) || (data.Length &lt;= 0))
                  return null;
  
              using (MemoryStream ms = new MemoryStream(data))
              {
                  try
                  {
                      return new Icon(ms, 16, 16);
                  }
                  catch (ArgumentException)
                  {
                      // May not be an icon file.
                      using (Bitmap b = new Bitmap(ms))
                          return Icon.FromHandle(b.GetHicon());
                  }
              }
          }
      }
  </code></pre>
  
  <p>and this is how i did it with WinForm browser:</p>
  
  <pre><code> private void webBrowser1_DocumentCompleted(object sender,   WebBrowserDocumentCompletedEventArgs e)
   {
          UpdateFavicon();
   }
   private void UpdateFavicon()
   {
     var obj = webBrowser1.Document.InvokeScript("_X_");
     string val = webBrowser1.DocumentText = "&lt;script&gt; function _X_(){return " + JS_FAVICON + ";} &lt;/script&gt;"; 
   }
  </code></pre>