Search code examples
internet-explorervb6ieframe.dll

How to log to console when using IEFrame.dll


I'm working on a legacy application that is written in VB6 and uses the IEFrame.dll. There is some JavaScript that is not running consistently and I'd like to write some logs somewhere to help figure out what is going on. Is this even possible with IEFrame.dll?


Solution

  • It might make some people cringe, but consider the following:

    sample.htm

    <html xmlns:custom>
        <body>
            <custom:generic id="Logging" style="inline:true;display:none"/>
    
            <button onclick="Logging.innerText='Hello';Logging.click()">Click me 1</button>
            &nbsp;
            <button onclick="Logging.innerText='Goodbye';Logging.click()">Click me 2</button>
        </body>
    </html>
    

    Form1.frm

    Option Explicit
    
    'Reference to: Microsoft HTML Object Library
    
    Private WithEvents Logging As MSHTML.HTMLGenericElement
    
    Private Sub Form_Load()
        WebBrowser1.Navigate2 App.Path & "\sample.htm"
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            WebBrowser1.Move 0, 0, ScaleWidth, ScaleHeight
        End If
    End Sub
    
    Private Function Logging_onclick() As Boolean
        Debug.Print Logging.innerText
    End Function
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        Set Logging = pDisp.Document.All("Logging")
    End Sub