Results 1 to 5 of 5

Thread: Return value from CallDevToolsProtocolMethod from RC6/cWebView2

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2026
    Posts
    2

    Return value from CallDevToolsProtocolMethod from RC6/cWebView2

    I host WebView2 in my vb6 app using RC6. I would like to call CallDevToolsProtocolMethod Page.printToPDF and get the base64 of the pdf back, but I believe the current version of RC6 does not provide a return value when calling CallDevToolsProtocolMethod, probably because it is async. I tried to check the various events but none trigger, so it seems there is no way to get the return value from CallDevToolsProtocolMethod Page.printToPDF.

    Any ideas?

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,179

    Re: Return value from CallDevToolsProtocolMethod from RC6/cWebView2

    Quote Originally Posted by pawlos2nd View Post
    I tried to check the various events but none trigger, so it seems there is no way to get the return value from CallDevToolsProtocolMethod Page.printToPDF.

    Any ideas?
    Did you try JSMessage event? It can be "manually" triggered by your JS code with something like vbH().RaiseMessageEvent('title_change', document.title) -- this will trigger JSMessage with sMsg = "title_change" and sMsgContent populated accordingly.

    Try implementing your async handler in JS so that on ready it just calls back into VB6 with simple vbH().RaiseMessageEvent passing unique 'pdf_ready' message type with base64 encoded PDF in second sMsgContent parameter.

    cheers,
    </wqw>

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2026
    Posts
    2

    Re: Return value from CallDevToolsProtocolMethod from RC6/cWebView2

    I appreciate your answer, but I dont think it works because Page.printToPDF is a DevTools Protocol method. Page JS cannot invoke CDP — there is no window/chrome.webview API for it, so JS has no "on ready" event and never receives printToPDF's base64?

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,179

    Re: Return value from CallDevToolsProtocolMethod from RC6/cWebView2

    Yes, I see -- my bad I didn't realize CallDevToolsProtocolMethod is a method of cWebView2 which you probably call with something like

    Code:
       '--- CDP options: sizes in INCHES (A4 = 8.27 x 11.69)
       sParams = "{""printBackground"":true," & _
                 """paperWidth"":8.27,""paperHeight"":11.69," & _
                 """marginTop"":0.4,""marginBottom"":0.4," & _
                 """marginLeft"":0.4,""marginRight"":0.4," & _
                 """preferCSSPageSize"":true}"
    
       '--- Invoke CDP; returns {"data":"<base64>"}
       Call WV.CallDevToolsProtocolMethod("Page.printToPDF", sParams)
    Olaf will have to chime in but by the looks of it I think there is probably a completion event missing by the wrapper the same way DocumentTitleChanged event is missing and has to be handled in JS as a workaround.

    cheers,
    </wqw>

  5. #5
    Junior Member woeoio's Avatar
    Join Date
    Jan 2022
    Posts
    24

    Re: Return value from CallDevToolsProtocolMethod from RC6/cWebView2

    Perhaps you can try the webview2 component of vbman2:
    Code:
    Dim wv As New cWebView2Host
    
    Private Sub Form_Load()
        wv.Initialize Me.hWnd, "https://vb6.pro/"
    End Sub
    
    Private Sub MenuSendCDP_Click()
        '--- 1. Get page title ---
        Dim sTitle As String
        sTitle = wv.CallDevToolsProtocolMethodSync("Runtime.evaluate", "{""expression"":""document.title""}")
        Debug.Print "[Sync] Title -> " & sTitle
        
        '--- 2. Get all cookies ---
        Dim sCookies As String
        sCookies = wv.CallDevToolsProtocolMethodSync("Network.getCookies", "{}")
        Debug.Print "[Sync] Cookies -> " & sCookies
        
        '--- 3. Get page URL ---
        Dim sUrl As String
        sUrl = wv.CallDevToolsProtocolMethodSync("Runtime.evaluate", "{""expression"":""document.URL""}")
        Debug.Print "[Sync] URL -> " & sUrl
        
        '--- 4. Get browser version ---
        Dim sVersion As String
        sVersion = wv.CallDevToolsProtocolMethodSync("Browser.getVersion", "{}")
        Debug.Print "[Sync] Browser Version -> " & sVersion
        
        '--- 5. Show title in MsgBox ---
        MsgBox "Title: " & sTitle, vbInformation, "CDP Sync Demo"
    End Sub
    CDP Guide - Chrome DevTools Protocol Calling Guide | VB6 PRO DOCS
    https://doc.vb6.pro/en/vbman2/webview2/cdp.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width