none
Cefsharp popups lifespanhandler RRS feed

  • Pregunta

  • Hola gente. Vengo con una consulta que me tiene de los pelos. Consulto por aca ya que todo lo que hay sobre cefsharp está en c y no logro portar con propiedad...

    Utilizo cef para cargar un framework, funciona bien... Pero lo que necesito es poder manejar de forma manual los popups, o childs.. creé un nuevo form con un panel, al cual necesito poder mandarle la variable de la url que de momento, estoy bloqueando con la clase...

    Hasta el momento, pude lograr bloquear los clicks que dirigen a <a href="#" "_blank" />

    Imports CefSharp.WinForms
    Imports CefSharp
    Imports myapp.popupscefsharp
    
    Public Class backend
    
        Private WithEvents navegadorweb As ChromiumWebBrowser
        Private Property IsBrowserInitialized As Boolean
        Public Sub New()
            InitializeComponent()
            Dim settings As New CefSettings()
            settings.CachePath = ""
            settings.WindowlessRenderingEnabled = True
            settings.PersistSessionCookies = True
            settings.PersistUserPreferences = True
            settings.LogFile = "logcat.txt"
            CefSharp.Cef.Initialize(settings)
    
            navegadorweb = New ChromiumWebBrowser(String.Empty)
            Dim life As LifespanHandler = New LifespanHandler()
            navegadorweb.LifeSpanHandler = life
            navegadorweb.Load("C:\XXX\XXX\penetrador.html")
            navegador.Controls.Add(navegadorweb)
        End Sub
    
        Private Async Sub navegadorweb_LoadingStateChanged(ByVal sender As Object, ByVal e As LoadingStateChangedEventArgs) Handles navegadorweb.LoadingStateChanged
            If Not e.Browser.IsLoading Then
                Await Task.Run(Async Function()
                                   Await Task.Delay(0)
                               End Function)
                Try
                    navegadorweb.ExecuteScriptAsync("document.getElementById('xxx').click();")
                    navegadorweb.ExecuteScriptAsync("document.oncontextmenu = function() { return false; };")
                Catch ex As Exception
                End Try
            End If
        End Sub
    
        Private Sub backend_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            CefSharp.Cef.Shutdown()
            Application.Exit()
        End Sub
    End Class


    Utilizo la siguiente clase, que he modificado desde su fuente en c, para hacerla arrancar...

    Imports CefSharp
    
    Namespace popupscefsharp
        Public Class LifespanHandler
            Implements ILifeSpanHandler
    
            Public Event popup_request As Action(Of String)
    
            Private Function ILifeSpanHandler_OnBeforePopup(chromiumWebBrowser As IWebBrowser, browser As IBrowser, frame As IFrame, targetUrl As String, targetFrameName As String, targetDisposition As WindowOpenDisposition, userGesture As Boolean, popupFeatures As IPopupFeatures, windowInfo As IWindowInfo, browserSettings As IBrowserSettings, ByRef noJavascriptAccess As Boolean, ByRef newBrowser As IWebBrowser) As Boolean Implements ILifeSpanHandler.OnBeforePopup
                RaiseEvent popup_request(targetUrl)
                newBrowser = Nothing
                Return True
            End Function
    
            Private Sub ILifeSpanHandler_OnAfterCreated(chromiumWebBrowser As IWebBrowser, browser As IBrowser) Implements ILifeSpanHandler.OnAfterCreated
                
            End Sub
    
            Private Function ILifeSpanHandler_DoClose(chromiumWebBrowser As IWebBrowser, browser As IBrowser) As Boolean Implements ILifeSpanHandler.DoClose
                Return False
            End Function
    
            Private Sub ILifeSpanHandler_OnBeforeClose(chromiumWebBrowser As IWebBrowser, browser As IBrowser) Implements ILifeSpanHandler.OnBeforeClose
    
            End Sub
        End Class
    End Namespace
    

    Básicamente, necesito poder abrir todos los enlaces externos en un único form creado manualmente.

    Si alguien tiene alguna idea de como implementar bien el lifespanhandler en vb.net o alguna documentación, agradezco link.

    Saludos.

    sábado, 15 de febrero de 2020 22:48