OnBeforeResourceLoad not called for some XHRs

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

OnBeforeResourceLoad not called for some XHRs

Postby rado » Tue Oct 10, 2023 4:29 pm

I have one 3rd party site where OnBeforeResourceLoad handler is not called for some XHR requests located at the site's domain (tested in cefclient / 115.3.10 win32). It works for one particular XHR request which is the first, but not for next requests. I cannot find any relevant difference, at least not in URL. Both requests have this structure, just different end of the URL and different cookies: (taken from fiddler)

Code: Select all
GET /api/v1/*** HTTP/1.1
Host: ***.com
Connection: keep-alive
sec-ch-ua: "Chromium";v="115", "Not/A)Brand";v="99"
sec-ch-ua-mobile: ?0
Authorization: ***
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36
Accept: application/json, text/plain, */*
sec-ch-ua-platform: "Windows"
Accept-Language: en-US,en;q=0.9
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://***.com/
Accept-Encoding: gzip, deflate, br
Cookie: ***


I've found this old thread: https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=16926 but there is no solution.
Any idea what could be wrong? Is there some known limitation for this handler?
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: OnBeforeResourceLoad not called for some XHRs

Postby magreenblatt » Tue Oct 10, 2023 5:50 pm

It works for one particular XHR request which is the first, but not for next requests.

Are all requests using the same URL? If so, perhaps the responses are being cached.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforeResourceLoad not called for some XHRs

Postby rado » Wed Oct 11, 2023 12:31 am

magreenblatt wrote:
It works for one particular XHR request which is the first, but not for next requests.

Are all requests using the same URL? If so, perhaps the responses are being cached.

URL is almost the same, except last segment after /. I can see in the fiddler requests are invoked.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: OnBeforeResourceLoad not called for some XHRs

Postby rado » Wed Oct 11, 2023 12:19 pm

It's unrealistic for me to build and debug the cef/chromium so at least I'd like to see how this callback works, so I've set breakpoint to the handler and set the debug symbols, but when I walk the stack trace I'd need the source codes used to build the cef downloaded from the spotify. Is it possible to get appropriate sources somewhere?
Maybe I could see some potential place in the callstack where calling the callback could go wrong way.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: OnBeforeResourceLoad not called for some XHRs

Postby rado » Sat Oct 14, 2023 4:47 pm

So I've found the service worker requests are handled different way. So I've added CefRequestContextHandler::GetResourceRequestHandler() to the cefclient application. Now for one tested site I'm getting service worker's requests to CefRequestContextHandler so I guess I've handled it correctly. However neither CefRequestContextHandler nor CefRequestHandler handler is called for some requests at other site. I've downloaded sources for chromium and cef. Although I've downloaded versions listed in cef's binary distribution name, debugger says some sources are different. I can still debug something and I've found out it has trouble to find handler here
Code: Select all
CefRefPtr<CefRequestContextHandler> CefIOThreadState::GetHandler(
    const content::GlobalRenderFrameHostId& global_id,
    bool require_frame_match) const {
  CEF_REQUIRE_IOT();
  return handler_map_.GetHandler(global_id, require_frame_match);
}


Currently the global_id has value child_id=30, frame_routing_id=-2, but in the handler_map_ there are only handlers with child_id in (26,27,28).
The request looks like this In the developer tools:
req_reset.png
req_reset.png (8.21 KiB) Viewed 11540 times

Domain is the same as main page. Any ide what can be wrong? I can send here the page here if somebody would try it.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: OnBeforeResourceLoad not called for some XHRs

Postby magreenblatt » Sat Oct 14, 2023 6:14 pm

Although I've downloaded versions listed in cef's binary distribution name, debugger says some sources are different.

You need to apply the Chromium patch files from the cef/patches directory.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforeResourceLoad not called for some XHRs

Postby rado » Sun Oct 15, 2023 6:20 am

magreenblatt wrote:You need to apply the Chromium patch files from the cef/patches directory.

Is it possible to do this without running complete automate-git.py? For me it is running for hours and it didn't even start compiling.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: OnBeforeResourceLoad not called for some XHRs

Postby magreenblatt » Sun Oct 15, 2023 9:14 am

You can download source code archives for CEF and Chromium. See https://bitbucket.org/chromiumembedded/ ... nsupported
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforeResourceLoad not called for some XHRs

Postby rado » Sun Oct 15, 2023 12:02 pm

I was following this instructions: https://bitbucket.org/chromiumembedded/ ... ckStart.md
but I've added the " --branch=5938" to update.bat so now it is
Code: Select all
set GN_DEFINES=is_component_build=true
set GN_ARGUMENTS=--ide=vs2022 --sln=cef --filters=//cef/*
python3 ..\automate\automate-git.py --download-dir=c:\code\chromium_git --depot-tools-dir=c:\code\depot_tools --no-distrib --no-build --branch=5938

It finished and in CHROMIUM_BUILD_COMPATIBILITY.txt there is "'chromium_checkout': 'refs/tags/117.0.5938.152'.
I'm using it with spotify build cef_binary_117.2.5+gda4c36a+chromium-117.0.5938.152_windows32.tar.bz2
I guess patches should be applied automatically because this step is not mentioned, but VS still says some sources are different than used for build. So I've checked manually C:\code\chromium_git\chromium\src\base\message_loop\message_pump_win.cc
And it seems to me it was not patched. Is there some problem, or do I need to apply patches manually? How?

The step 7 - 7. Create the "c:\code\chromium_git\chromium\src\cef\create.bat" script with the following contents....
does not work for me
Code: Select all
C:\code\chromium_git\chromium\src\cef>call cef_create_projects.bat                                                                                                  'cef_create_projects.bat' is not recognized as an internal or external command,                                                                                     operable program or batch file.

But I guess I don't need that anyway since I'm not going to build it.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: OnBeforeResourceLoad not called for some XHRs

Postby magreenblatt » Sun Oct 15, 2023 1:00 pm

Running cef_create_projects.bat will apply the patch files. Run using a cmd.exe shell and drop the “call” prefix.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 211 guests