Page 1 of 2
SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 9:46 am
by bullsito
I am trying to Subscribe to Developer tools event with no luck.
after creating the edge component i do
WVBrowser1.SubscribeToDevToolsProtocolEvent('Log.enable');
WVBrowser1.SubscribeToDevToolsProtocolEvent('Log.entryAdded');
and WVBrowser1DevToolsProtocolEventReceived never fires
Do i need something else ?
also I am trying to send a custom response
On webresource request event i do the follow
mydata:='hello world';
m:=Tmemorystream.Create;
try
m.Write(mydata[1], length(mydata) * SizeOf(mydata[1]));
m.Position:=0;
TempAdapter := TStreamAdapter.Create(m);
try
if Succeeded(wb.EnvironmentInterface.CreateWebResourceResponse(TempAdapter, 200 , '', 'Content-Type: text/plain', lResponse)) then Args.ArgsInterface.Set_Response(lResponse);
finally
TempAdapter:=nil;
end;
finally
freeandNil(m);
end;
but also is not working.
Any help ????
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 1:01 pm
by salvadordf
Hi,
I just added the
SubscribeToDevToolsProtocolEventBrowser demo showing how to subscribe to that event.
Please, download WebView4Delphi again from GitHub.
These are the steps followed by that demo to subscribe to that event :
- First it enables the "Log" domain with a TWVBrowser.CallDevToolsProtocolMethod call in the TWVBrowser.OnAfterCreated event. Notice that it uses a custom LOG_ENABLE_CMD constant and an empty JSON parameter "{}".
- After that, the TWVBrowser.OnCallDevToolsProtocolMethodCompleted event checks that the aExecutionID is LOG_ENABLE_CMD to subscribe to the event with a TWVBrowser.SubscribeToDevToolsProtocolEvent call. Notice that it uses the custom LOG_ENTRYADDED_EVENT constant as parameter.
- The TWVBrowser.OnDevToolsProtocolEventReceived event receives all subcribed DevTool events and it checks that aEventID is LOG_ENTRYADDED_EVENT before handling the aArgs parameter.
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 1:29 pm
by salvadordf
About the webresource request event, check the MiniBrowser demo.
It has an image filter menu option that has all the code you need.
It calls TWVBrowser.AddWebResourceRequestedFilter to start receiving the TWVBrowser.OnWebResourceRequested events.
The TMiniBrowserFrm.WVBrowser1WebResourceRequested procedure shows how to create a custom ICoreWebView2WebResourceResponse instance.
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 2:49 pm
by bullsito
thank you so much checking now!
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 3:05 pm
by bullsito
salvadordf wrote: Sun Apr 24, 2022 1:01 pm
Hi,
I just added the
SubscribeToDevToolsProtocolEventBrowser demo showing how to subscribe to that event.
Please, download WebView4Delphi again from GitHub.
These are the steps followed by that demo to subscribe to that event :
- First it enables the "Log" domain with a TWVBrowser.CallDevToolsProtocolMethod call in the TWVBrowser.OnAfterCreated event. Notice that it uses a custom LOG_ENABLE_CMD constant and an empty JSON parameter "{}".
- After that, the TWVBrowser.OnCallDevToolsProtocolMethodCompleted event checks that the aExecutionID is LOG_ENABLE_CMD to subscribe to the event with a TWVBrowser.SubscribeToDevToolsProtocolEvent call. Notice that it uses the custom LOG_ENTRYADDED_EVENT constant as parameter.
- The TWVBrowser.OnDevToolsProtocolEventReceived event receives all subcribed DevTool events and it checks that aEventID is LOG_ENTRYADDED_EVENT before handling the aArgs parameter.
Thank you for your example what ebout subscrible to Network.webSocketFrameReceived
is anyway to log the data to my memo ?
i cannot call it maybe the {} needs some extra parametrs
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 3:09 pm
by bullsito
salvadordf wrote: Sun Apr 24, 2022 1:29 pm
About the webresource request event, check the MiniBrowser demo.
It has an image filter menu option that has all the code you need.
It calls TWVBrowser.AddWebResourceRequestedFilter to start receiving the TWVBrowser.OnWebResourceRequested events.
The TMiniBrowserFrm.WVBrowser1WebResourceRequested procedure shows how to create a custom ICoreWebView2WebResourceResponse instance.
I have seen this example the problem is how to pass my own BODY to the response
WVBrowser1.CoreWebView2Environment.CreateWebResourceResponse(nil, 200, '', 'Content-Type: text/html, TempResponse)
i suppose nil needs to have a Stream or something?
How can i sent my own response from a string?
thank you anyway
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 3:13 pm
by salvadordf
The Network.enable method has some optional parameters but I guess it should work with a simple {}
https://chromedevtools.github.io/devtools-protocol/1-3/Network/#method-enable
Remember that WebView2 might not support all DevTools methods and events. Read this for more information about them :
https://chromedevtools.github.io/devtools-protocol/1-3/
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 3:20 pm
by salvadordf
bullsito wrote: Sun Apr 24, 2022 3:09 pm
salvadordf wrote: Sun Apr 24, 2022 1:29 pm
About the webresource request event, check the MiniBrowser demo.
It has an image filter menu option that has all the code you need.
It calls TWVBrowser.AddWebResourceRequestedFilter to start receiving the TWVBrowser.OnWebResourceRequested events.
The TMiniBrowserFrm.WVBrowser1WebResourceRequested procedure shows how to create a custom ICoreWebView2WebResourceResponse instance.
I have seen this example the problem is how to pass my own BODY to the response
WVBrowser1.CoreWebView2Environment.CreateWebResourceResponse(nil, 200, '', 'Content-Type: text/html, TempResponse)
i suppose nil needs to have a Stream or something?
How can i sent my own response from a string?
thank you anyway
The MiniBrowser example is a translation of the sample code in the WebView2 documentation. I've never replaced the body but this code might help you :
https://github.com/salvadordf/WebView4Delphi/blob/b125c1afd33d18c6dcae986831b4d9b5f53b1e83/demos/Delphi_VCL/NavigateWithWebResourceRequestBrowser/uNavigateWithWebResourceRequestBrowser.pas#L97
See the WebView2 API documentation for more details :
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 6:26 pm
by bullsito
salvadordf wrote: Sun Apr 24, 2022 3:13 pm
The
Network.enable method has some optional parameters but I guess it should work with a simple {}
https://chromedevtools.github.io/devtools-protocol/1-3/Network/#method-enable
Remember that WebView2 might not support all DevTools methods and events. Read this for more information about them :
https://chromedevtools.github.io/devtools-protocol/1-3/
WORKED like a charm!!!!!!
So kind of you thanks for your time.
it is a great component!
Re: SubscribeToDevToolsProtocolEvent
Posted: Sun Apr 24, 2022 6:32 pm
by bullsito
salvadordf wrote: Sun Apr 24, 2022 3:20 pm
[
The MiniBrowser example is a translation of the sample code in the WebView2 documentation. I've never replaced the body but this code might help you :
https://github.com/salvadordf/WebView4Delphi/blob/b125c1afd33d18c6dcae986831b4d9b5f53b1e83/demos/Delphi_VCL/NavigateWithWebResourceRequestBrowser/uNavigateWithWebResourceRequestBrowser.pas#L97
See the WebView2 API documentation for more details :
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/
I do not want to replace the body i need to Inject code to the body before render.
so i need to have access to the body content then add some lines in the body and then serve it.
is this possible with Chef4 Chromium or Webview?