Webbrowser problem to click on elements of the site

Asked

Viewed 1,315 times

1

Hey there, guys! I need to access this link: https://br.answers.yahoo.com/question/index?qid=20140809134831AAoevh8

Using IE, Chrome, Firefox... any browser I can normally with no errors, but when trying to access this link through Webbrowser the site simply gets bugged.

1) I’ll explain further: There is an area below the page for comments. A photo for better understanding: http://i.imgur.com/Au5zguf.png

2) When I click on this textarea to comment, quickly in any browser the component lengthens. A photo for better understanding: http://i.imgur.com/Mcqimyw.png

However, when accessing this same link using Webbrowser, by clicking on the comments textarea, nothing happens. The page element remains in the starting position, as if I hadn’t even clicked...

Can someone give me a light of what is happening and how I can solve this problem?

Thank you in advance!

  • script error when trying to open the ? page http://i.stack.Imgur.com/Ueoq1.png

  • 1

    Wesley, I believe you’re adding a Webbrowser to a Desktop application, possibly Webforms or WPF. In any case, I advise you to use Cefsharp (https://github.com/cefsharp/CefSharp) to extend Webbrowser’s ability, so it will use Chromium Embedded Framework instead of an older embedded version of IE (which should not know what HTML5, CC3 or Ecmascript 5 is).

  • Yes, Thiago Falcão! Several script errors happen One photo: http://i.imgur.com/t2pI6QS.png

  • Hello, Tobymosque! I took a look at Cefsharp here. I think this might be the solution... change the browser engine, but I wanted to know why the same error you know, if there is any way to solve because I really like the Webbrowser of Visual Studio.

1 answer

1


I’m doing an advanced browser and edited a lot on it to remove script errors and render the page better, but I’ll share some of my code to see if it can help you.

'Coloque isso no método iniciador da forma principal (Form1)
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(Function() True)

Ok, then it will ignore certificate errors, but it will not make sense now, put this line, has to be the first expression of the event Load of your WebBrowser:

 'Ao carregar seu Webbrowser (WebBrowser1.Load):
 WebBrowser1.ScriptErrorsSuppressed = True

Beauty, by default Webbrowser is rendered by the renderer of Internet Explorer 7 (unfortunately), but fortunately we can put to the higher version, in case the IE 11.

That part is what will make the most difference, put that code in the file Application.Designer.Vb

Located in the directory of your project, goes in the folder My Project and the file will be there.

Put this method Namespace My.MyApplication:

  Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
     CreateBrowserKey()
  End Sub

  Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
     ' Se quiser que remova a propriedade:
     ' RemoveBrowerKey()
  End Sub

  Private Const BrowserKeyPath As String = "\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"

  Private Sub CreateBrowserKey(Optional ByVal IgnoreIDocDirective As Boolean = False)
     Dim basekey As String = Microsoft.Win32.Registry.CurrentUser.ToString
     Dim value As Int32
     Dim thisAppsName As String = My.Application.Info.AssemblyName & ".exe"

     ' Value reference: http://msdn.microsoft.com/en-us/library/ee330730%28v=VS.85%29.aspx
     ' IDOC Reference:  http://msdn.microsoft.com/en-us/library/ms535242%28v=vs.85%29.aspx
     Select Case (New WebBrowser).Version.Major
        Case 8 'Internet Explorer 8
           If IgnoreIDocDirective Then
              value = 8888
           Else
              value = 8000
           End If

        Case 9 'IE 9
           If IgnoreIDocDirective Then
              value = 9999
           Else
              value = 9000
           End If
        Case 10 'IE 10
           If IgnoreIDocDirective Then
              value = 10001
           Else
              value = 10000
           End If

        Case 11 'IE 11
           If IgnoreIDocDirective Then
              value = 11001
           Else
              value = 11000
           End If

        Case Else ' não achou o ie?!
           Exit Sub

     End Select

     Microsoft.Win32.Registry.SetValue(Microsoft.Win32.Registry.CurrentUser.ToString & BrowserKeyPath,
                                       Process.GetCurrentProcess.ProcessName & ".exe",
                                       value,
                                       Microsoft.Win32.RegistryValueKind.DWord)
  End Sub

  Private Sub RemoveBrowerKey()
     Dim key As Microsoft.Win32.RegistryKey
     key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(BrowserKeyPath.Substring(1), True)
     key.DeleteValue(Process.GetCurrentProcess.ProcessName & ".exe", False)
  End Sub

Try to do it, hugs!

Tip: If you can’t find the file, put these methods on Form1.

  • 1

    Hello, Cypherpotato! Cara worked!!! This idea to change the IE version is really good! Thanks, you saved me ;) Just a question came up, the requirement then for a user to use the program without problems is to have a version of IE between 8 and 11 installed on the machine, right?

  • That one Select Case will get the largest version of Internet Explorer installed on the computer, if the user has the 11, will render the site as the 11, you have the 10, will render with the 10, and so on...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.