Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

SubscribeToDevToolsProtocolEvent

bullsito
Posts: 32
Joined: Sun Dec 13, 2020 4:19 pm

SubscribeToDevToolsProtocolEvent

Post 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 ????
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SubscribeToDevToolsProtocolEvent

Post 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.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SubscribeToDevToolsProtocolEvent

Post 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.
bullsito
Posts: 32
Joined: Sun Dec 13, 2020 4:19 pm

Re: SubscribeToDevToolsProtocolEvent

Post by bullsito »

thank you so much checking now!
bullsito
Posts: 32
Joined: Sun Dec 13, 2020 4:19 pm

Re: SubscribeToDevToolsProtocolEvent

Post 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
bullsito
Posts: 32
Joined: Sun Dec 13, 2020 4:19 pm

Re: SubscribeToDevToolsProtocolEvent

Post 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
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SubscribeToDevToolsProtocolEvent

Post 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/
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: SubscribeToDevToolsProtocolEvent

Post 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/
bullsito
Posts: 32
Joined: Sun Dec 13, 2020 4:19 pm

Re: SubscribeToDevToolsProtocolEvent

Post 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!
bullsito
Posts: 32
Joined: Sun Dec 13, 2020 4:19 pm

Re: SubscribeToDevToolsProtocolEvent

Post 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?
Post Reply