|
-
Jun 8th, 2026, 05:48 PM
#1
Thread Starter
New Member
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?
-
Jun 9th, 2026, 04:42 AM
#2
Re: Return value from CallDevToolsProtocolMethod from RC6/cWebView2
 Originally Posted by pawlos2nd
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>
-
Jun 9th, 2026, 05:41 AM
#3
Thread Starter
New Member
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?
-
Jun 9th, 2026, 07:44 AM
#4
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>
-
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|