none
WebBrowser script error when using google maps

    Question

  • Can't find anything related to this, so there is my entry on this.

    Until a few weeks my app would work perfectly with webbrowser control and google maps(With this i mean, my app would show the route between 2 points on a webbrowser control). This week on monday i got a call from a customer complaining about a script error on my app, and that they couldnt see the google maps anymore, and indeed there is a problem, whenever i try to call the webbrowser from code i got a script error window with the information:

    Error: InvalidCharachterError

    Like i said this have been working so far until this week. I havent found anything on this problem.

    Im using wpf with vb.net and on my usercontrol code i have:

    Dim URLExample As String = "http://maps.google.nl/maps?f=d&hl=nl&geocode=&saddr=Lijnbaan+3d,+3252CK+Leiderdorp&daddr=3064+HW+Vleutenseweg+386-,+Utrecht&dirflg=h"       

    web_view.Navigate(New Uri(URLExample ))

    that url is just an example. The same url works on both google chrome and Internet explorer without any error, only when is used from the webbrowser control.

    Things i have done:

    Hide script errors with supress

    add maps.google to trusted web sites

    enable scripts on browser

    change uri function to anotherURI("transparent", url) that i found on this forum(didnt work)

    Thanks for reading and i hope you can help me.

    Sorry if i sounded rude but i really dont meant to.

    EDIT: even by going to https://maps.google.com i got the script error.

    Regards,

    Rui Nunes




    • Edited by Delf0 Thursday, October 10, 2013 3:11 PM New information
    Thursday, October 10, 2013 3:03 PM

Answers

  •  
     Private Sub IEbrowserFix()
            Try
                Dim regDM As Microsoft.Win32.RegistryKey
                Dim is64 As Boolean = Environment.Is64BitOperatingSystem
                Dim KeyPath As String = ""
                If is64 Then
                    KeyPath = "SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
                Else
                    KeyPath = "SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
                End If
    
                regDM = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KeyPath, False)
                If regDM Is Nothing Then
                    regDM = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(KeyPath)
                End If
    
                Dim Sleutel As Object
                If Not regDM Is Nothing Then
                    Dim location As String = System.Environment.GetCommandLineArgs()(0)
                    Dim appName As String = System.IO.Path.GetFileName(location)
    
                    Sleutel = regDM.GetValue(appName)
                    If Sleutel Is Nothing Then
                        'Sleutel onbekend
                        regDM = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KeyPath, True)
                        Sleutel = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(KeyPath, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree)
    
                        'What OS are we using
                        Dim OsVersion As Version = System.Environment.OSVersion.Version
    
                        If OsVersion.Major = 6 And OsVersion.Minor = 1 Then
                            'WIN 7
                            Sleutel.SetValue(appName, 9000, Microsoft.Win32.RegistryValueKind.DWord)
                        ElseIf OsVersion.Major = 6 And OsVersion.Minor = 2 Then
                            'WIN 8
                            Sleutel.SetValue(appName, 10000, Microsoft.Win32.RegistryValueKind.DWord)
                        ElseIf OsVersion.Major = 5 And OsVersion.Minor = 1 Then
                            'WIN xp
                            Sleutel.SetValue(appName, 8000, Microsoft.Win32.RegistryValueKind.DWord)
                        End If
    
                        Sleutel.Close()
                    End If
                End If
    
    
            Catch ex As Exception
                WriteErrorLog("", "", ex)
            End Try
        End Sub

    There you go, this fixed my problem, hopefully will help some poor soul and take them less time to find a solution than i did! :) Cheers

    Regards,

    Rui Nunes

    • Marked as answer by Delf0 Friday, October 11, 2013 9:11 AM
    Friday, October 11, 2013 8:28 AM

All replies

  • I just created a simple sample using the URL you provided.  The webbrowser displayed the route and the map without a problem.

    Lloyd Sheen

    Thursday, October 10, 2013 3:25 PM
  • i(dot)imgur(dot)com/WWVeTJW.jpg

    Cant put links yet, replace (dot) by real dots

    Well then i should just throw my pc againt the wall i guess!

    Thursday, October 10, 2013 4:00 PM
  • Before you destroy your PC, I have had problems where clearing the internet cache fixed the problem.  At times the javascript which does all the work sometimes needs to be reloaded as you may have an older package and there is no notification from google that they have changed the code.  Just a thought.

    Lloyd Sheen

    Thursday, October 10, 2013 4:39 PM
  • I think I can confirm the same issue. It started cropping up about a week ago. Our app is a .net 4.0 WinForms based app. We embed System.Windows.Forms.WebBrowser control in our application that load Google Maps URL's.

    Simply creating a test solution in Visual Studio with

    private void Form1_Load(object sender, EventArgs e)
    {
        string googleMaps = @"https://maps.google.com/?q=400+Broadway,+San+Diego,+California,+92101";
        webBrowser1.Navigate(googleMaps);
    }

    Throws the error:

    Thursday, October 10, 2013 5:49 PM
  • Thats what i have been getting this week! I'm still looking for a easy solution, i really don't want to change my control to something else just because of this. There has to be a solution :(
    Thursday, October 10, 2013 8:27 PM
  • What's the version of your system & IE ?

    This issue also occured in my sample LoL:

    Windows 8, IE 10


    Best Regards,
    Please remember to mark the replies as answers if they help

    • Edited by IssueKiller Friday, October 11, 2013 2:09 AM
    Friday, October 11, 2013 2:09 AM
  • it has been happening with all OS and IE versions. For windows 7 i found a solution but still no solution for windows 8:

    For windows 7 it looks like if we change something on the registry of the pc it will work just fine, the solution that i found is on this link: www(dot)overclock(dot)net/t/1189387/solved-c-webbrowser-and-scripted-pages-totally-lost/10  

    As it says there we have to add our app name and then give a binary number depending of the IE version we are using. I.E.: for windows 7 with IE 8 we can use the value 9000 and it works, but looking at the msdn web site the value 10000 doesnt work for windows 8 with IE 10. Any how if anyone find a solution for Windows 8 with IE10 i would love to see it too :)

    Sorry but im not able to put links yet! replace (dot) by real dots

    Regards

    Rui Nunes

    Friday, October 11, 2013 7:17 AM
  •  
     Private Sub IEbrowserFix()
            Try
                Dim regDM As Microsoft.Win32.RegistryKey
                Dim is64 As Boolean = Environment.Is64BitOperatingSystem
                Dim KeyPath As String = ""
                If is64 Then
                    KeyPath = "SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
                Else
                    KeyPath = "SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
                End If
    
                regDM = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KeyPath, False)
                If regDM Is Nothing Then
                    regDM = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(KeyPath)
                End If
    
                Dim Sleutel As Object
                If Not regDM Is Nothing Then
                    Dim location As String = System.Environment.GetCommandLineArgs()(0)
                    Dim appName As String = System.IO.Path.GetFileName(location)
    
                    Sleutel = regDM.GetValue(appName)
                    If Sleutel Is Nothing Then
                        'Sleutel onbekend
                        regDM = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KeyPath, True)
                        Sleutel = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(KeyPath, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree)
    
                        'What OS are we using
                        Dim OsVersion As Version = System.Environment.OSVersion.Version
    
                        If OsVersion.Major = 6 And OsVersion.Minor = 1 Then
                            'WIN 7
                            Sleutel.SetValue(appName, 9000, Microsoft.Win32.RegistryValueKind.DWord)
                        ElseIf OsVersion.Major = 6 And OsVersion.Minor = 2 Then
                            'WIN 8
                            Sleutel.SetValue(appName, 10000, Microsoft.Win32.RegistryValueKind.DWord)
                        ElseIf OsVersion.Major = 5 And OsVersion.Minor = 1 Then
                            'WIN xp
                            Sleutel.SetValue(appName, 8000, Microsoft.Win32.RegistryValueKind.DWord)
                        End If
    
                        Sleutel.Close()
                    End If
                End If
    
    
            Catch ex As Exception
                WriteErrorLog("", "", ex)
            End Try
        End Sub

    There you go, this fixed my problem, hopefully will help some poor soul and take them less time to find a solution than i did! :) Cheers

    Regards,

    Rui Nunes

    • Marked as answer by Delf0 Friday, October 11, 2013 9:11 AM
    Friday, October 11, 2013 8:28 AM
  • Hi there

    I too have been tearing my hair out with this ridiculous problem.

    Very grateful for your solution - however I am getting an error of Requested registry access is not allowed when executing this line:

    regDM = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KeyPath,True)

    Any help appreciated!

    Thursday, October 17, 2013 10:59 AM
  • Hi there, im glad i could help with that problem, about the registry access make sure the user have permission to add/edit the registry on that pc.

    Monday, October 21, 2013 1:04 PM
  • Hi Rui, your solution works for me.

    Thanks.

    Thursday, October 24, 2013 3:24 PM
  • Hi

    I'm an administrator on this machine but still can't change the registry (through code - I can manually). Any help appreciated!

    Monday, October 28, 2013 1:40 PM
  • I'm faced with this same issue all of a sudden.

    @Rui - Looking at the script error and your fix, I'm missing how this is the fix and how did it all of sudden start happening? Any details appreciated :)


    greg

    Tuesday, October 29, 2013 1:04 PM
  • Here's what I found.....

    If I loaded up the webBrowser control like this

    WebBrowser1.Url = New Uri("maps.google.com/...")

    This worked until very recently. Now, all of a sudden,  I am getting an invalidcharactererror javascript error. I don't really care for Rui's approach as my end users will have all different rights and messing with the registry is a last resort in my book. So I decided to try something else....

    Dim sb As New StringBuilder
    sb.Append("<html>")
    sb.Append("<head>")
    sb.Append("</head")
    sb.Append("<body>")

    sb.Append("<iframe src =""" & url & """ height=""" & WebBrowser1.Height & """ width=""" & WebBrowser1.Width & """></iframe>")

    sb.Append("</body")
    sb.Append("</html>")

    WebBrowser1.DocumentText = sb.ToString

    You get the idea. I was going to add a meta tag to force IE into latest version (content="IE=edge")  but that doesn't even seem to be necessary. All is working again as expected!


    greg



    • Edited by gregsipes Tuesday, October 29, 2013 2:44 PM
    • Proposed as answer by Graeme SP Tuesday, October 29, 2013 2:54 PM
    Tuesday, October 29, 2013 2:41 PM
  • Fantastic, works great - thanks!
    Tuesday, October 29, 2013 2:54 PM
  • Hi Greg

    You are a life saver. Worked as hell for me.

    Many Thanks

    Kazi
    Wednesday, October 30, 2013 5:02 AM
  • Really very simple, thank you for your solution.

    Professor Lucas Itaquera

    Thursday, October 31, 2013 7:53 PM
  • Really getting sick of this. Now google have changed something & when I go to a google route map I get:

    To help protect the security of information you enter
    into this website, the publisher of this content does not allow it to be
    displayed in a frame.

    Is it unreasonable to expect 2 of the biggest companies in the world to actually make sure their products work together? No doubt, if we could actually get to them, they would blame each other.

    Tuesday, November 05, 2013 9:25 AM
  • The only answer seems to be to use Bing - no doubt that suits Microsoft ;-(
    • Proposed as answer by Dasa0001 Friday, November 08, 2013 5:07 PM
    • Unproposed as answer by Dasa0001 Friday, November 08, 2013 5:07 PM
    Tuesday, November 05, 2013 5:56 PM
  • I solved the problem by assigning the property WebBrowser ScriptErrorsSuppressed how true, in order not to show the error
    Friday, November 08, 2013 5:08 PM
  • I solved the problem by assigning the property WebBrowser ScriptErrorsSuppressed how true, in order not to show the error
    • Proposed as answer by Dasa0001 Friday, November 08, 2013 5:09 PM
    Friday, November 08, 2013 5:08 PM
  • Hi

    You are correct in that that suppresses the error but the script stops running at the error & the maps don't work.

    Friday, November 08, 2013 5:36 PM
  • Hi, in my case it showed the error but the functionality is correct
    Friday, November 08, 2013 8:24 PM
  • Have you an example in C#. my problem is how to translate this line

    sb.Append("<iframe src =""" & url & """ height=""" & WebBrowser1.Height & """ width=""" & WebBrowser1.Width & """></iframe>")

    thank you very much


    • Edited by Arielr Wednesday, November 20, 2013 11:18 PM
    Wednesday, November 20, 2013 11:16 PM
  • Thank you, that solved the problem for me. I am using a web control on a VFP form, but adding my exe into that section of the registry sorted it without any changes to my application.
    Friday, December 20, 2013 6:19 AM
  • Thanks Rui Nunes, you have just pin pointed my problem and I have just converted your codes to C# it went perfectly well with a little adjustments.

    zaqxen

    Monday, March 31, 2014 4:42 PM
  • can try injecting <meta http-equiv="X-UA-Compatible" content="IE=edge"> into the pages or use a page that has it and an IFRAME to host your real content

    Microsoft MVP J# 2004-2010, Borland Spirit of Delphi 2001

    Thursday, September 04, 2014 11:09 AM
  • can try injecting <meta http-equiv="X-UA-Compatible" content="IE=edge"> into the pages or use a page that has it and an IFRAME to host your real content

    Microsoft MVP J# 2004-2010, Borland Spirit of Delphi 2001


    Esto:  <meta http-equiv="X-UA-Compatible" content="IE=edge">  me salvó la vida. Es todo lo que hay que colocar en el archivo. FUNCIONA...!! MUCHAS GRACIAS POR EL APORTE.
    Saturday, February 21, 2015 1:52 PM
  • Great !!!   Thanks !!!
    Monday, February 23, 2015 7:04 PM
  • Hi ,

    I am facing same problem, i am really stuck in this error. Please help me to solve this issue. following is my code snippet.

    {

                StringBuilder query = new StringBuilder();
                query.Append("https://maps.google.com/maps?q=");
                string addr = tbx_location.Text;
                string state = (string)cbx_states.SelectedItem;
                if (addr != string.Empty)
                {
                    query.Append(addr + "," + "+");
                }
                query.Append(state + "," + "+");
                query.Append("USA" + "," + "+");
                MapWin mapWin = new MapWin(query.ToString());
                mapWin.ShowDialog();

    }

    where mapwin is a windows form object containing webrowser,

    wbMap.Navigate(query.ToString());

    Please help me to solve it.

    Thanks in Advance.

    Sunday, March 15, 2015 6:52 AM
  • Works perfectly EXCEPT

    my application is an ActiveX running in someone else's application.

    if i set the compatibility mode it also sets it for their application.

    then i find out when the main application is started the vendor deletes this registry key.

    so i am unable to use the solution above

    frustrating!

    Monday, May 30, 2016 3:15 PM
  • Hello, read this  

    http://cortesfernando.blogspot.com.ar/2011/12/gmap.html

    It was very useful for me,

    Monday, May 30, 2016 3:36 PM
  • The problem is that visual studio forces IE7 compatability mode on the webbrowser control. IE7 does not support JSON.

    As google update their maps support for medieval versions of IE are dropped.

    It's a disgrace that this has been going on for years and even now in VS2015 it still forces unsupported browsers.

    I can't believe the only solution with this is registry hacks, why isn't there a setting in the control to select the IE version - or to choose to use the version on the machine?

    Come on MS, you take £1000 a year from me for my subscription - at least give me updated software that works to use.

    Thursday, June 23, 2016 11:18 AM
  • Genius!!!
    Wednesday, June 29, 2016 8:15 PM