I use Leaflet in my WPF C# program. I want to draw polygon on the map. I use System.Windows.Forms.WebBrowser for showing the map:

    <WindowsFormsHost Name="wfhSample">
            <wf:WebBrowser x:Name="webBrowser" DocumentTitleChanged="wbWinForms_DocumentTitleChanged" />

I get script error from the leaflet every time I run the program with L.polygon(but it works without errors if I draw L.circle or L.marker or if I don't draw anything on the map) added to my map in leaflet.html file:

var polygon = L.polygon([
            [0.939, 0.68],
            [0.933, 0.66],
            [0.940, 0.67]
        ]).addTo(map);//shows map without polygon and with next error  

enter image description here

P.S. But when I open leaflet.html with Edge browser the polygon is drawn on the map without any problem. What is the reason of this error shows every time I run the program?

  • 1
    Obviously there is something in L.polygon code that System.Windows.Forms.WebBrowser component does not like. If you can debug JS when using System.Windows.Forms.WebBrowser, use leaflet-src.js and check where it goes wrong. Another possiblity would be to try the latest Leaflet 1.9.3.
    – TomazicM
    Nov 22, 2022 at 14:15
  • I've changed the Webbrowser to WebView and the error has gone. But now the map doesn't show png tiles. I have just a gray blank map with geometries drawn on the map. Nov 23, 2022 at 10:14
  • .png tiles are stored locally and are not shown. But map shows if i use L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 18, minZoom: 13 }).addTo(map); Nov 23, 2022 at 10:34
  • 1
    I'm not familiar with Microsoft WebView, so I can't help you here. See learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/debug
    – TomazicM
    Nov 23, 2022 at 11:45
  • So finally i've changed WebView to CEFSharp and it seems that everything shows fine Nov 24, 2022 at 6:59

2 Answers 2


Using of CefSharp instead of WebBrowser(also i tried webView that wasn't able to show .png map tiles) solved my problem.

installed it through nuget.

            Address="file:///C:/Users/user/source/repos/LeafletWpfCefSharp/LeafletWpfCefSharp/resources/leaflet.html" />

you should use some other web browser like CefSharp , it is open source because .net web browser is facing javascript errors when fetching maps from browser i also face this difficulty and solve this problem by implementing CefSharp . Moreover you can also go to do ScriptErrorSurpressed = true in properties of default web browser of .net framework to avoid javascript errors but it is more recomended to use CefSharp Chromium browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.