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?
Re: Return value from CallDevToolsProtocolMethod from RC6/cWebView2
Quote:
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>
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?
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>