SendProcessMessage doesn't work when using stored browser

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.

SendProcessMessage doesn't work when using stored browser

Postby Czarek » Mon Nov 11, 2024 10:02 am

I have a JavascriptAPI object which implements CefV8Handler. I am creating this object in CefRenderProcessHandler::OnContextCreated and am passing CefRefPtr<CefBrowser> to store as JavascriptAPI.cefBrowser_ member. Later when JavascriptAPI::Execute calls when I execute browser->GetMainFrame()->SendProcessMessage() then that message never arrives to browser process. When I use context->GetBrowser() instead of the cefBrowser_ stored property then process messaging works OK. Why would that be? I checked and both browsers return the same identifier, so I don't think I'm making a stupid mistake. Just letting know of this behavior. Fix is easy, however debugging took some time. It worked fine in some old CEF version when using stored browser object.

CEF version: 130.1.15+g34b05bb+chromium-130.0.6723.92
Available for hire. Projects: PHP Desktop, CEF Python and CEF C API. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1947
Joined: Sun Nov 06, 2011 2:12 am

Re: SendProcessMessage doesn't work when using stored browse

Postby magreenblatt » Mon Nov 11, 2024 10:49 am

What frame is your JavaScript code executing within? Is it the main frame?
magreenblatt
Site Admin
 
Posts: 12974
Joined: Fri May 29, 2009 6:57 pm

Re: SendProcessMessage doesn't work when using stored browse

Postby ndesktop » Mon Nov 11, 2024 12:42 pm

Maybe the frame was swapped/replaced?
ndesktop
Master
 
Posts: 894
Joined: Thu Dec 03, 2015 10:10 am

Re: SendProcessMessage doesn't work when using stored browse

Postby Czarek » Mon Nov 11, 2024 2:30 pm

Yes, it is main frame. It's a very simple html page, just clicking a link:

Code: Select all
<a href="javascript:phpdesktop.ToggleFullscreen()">
    phpdesktop.ToggleFullscreen()</a>
Available for hire. Projects: PHP Desktop, CEF Python and CEF C API. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1947
Joined: Sun Nov 06, 2011 2:12 am

Re: SendProcessMessage doesn't work when using stored browse

Postby Czarek » Mon Nov 11, 2024 2:37 pm

Before clicking a link there is a navigation occuring on a page. Here are some logs from app:
Code: Select all
- 20:32:56.157 DEBUG: App context initialized
- 20:32:56.157 INFO: Create main window
- 20:32:56.157 DEBUG: Window max width/height = 2480/1352
- 20:32:56.157 DEBUG: Browser window not found, hwnd = 3278524
- 20:32:56.157 DEBUG: Event WM_GETMINMAXINFO: could not fetch browser window
- 20:32:56.157 DEBUG: Create main browser
- 20:32:56.157 INFO: Runtime style: alloy
- 20:32:56.157 DEBUG: Store browser window, hwnd = 3278524
- 20:32:56.172 INFO: Main window was created, hwnd=3278524
- 20:32:56.188 DEBUG: Browser was created
- 20:32:56.188 DEBUG: Set browser for window
[15400:14016:1111/203256.451:WARNING:viz_main_impl.cc(85)] VizNullHypothesis is disabled (not a warning)
- 20:32:56.204 DEBUG: OnLoadingStateChange: loading=1, url=
- 20:32:56.000 DEBUG: Command line string for the renderer process: "C:\Users\cz\phpdesktop\phpdesktop\Release\phpdesktop-chrome.exe" --type=renderer --string-annotations=is-enterprise-managed=no --start-stack-profiler --user-data-dir="C:\Users\cz\phpdesktop\phpdesktop\Release\webcache" --no-sandbox --remote-debugging-port=64095 --disable-gpu-compositing --video-capture-use-gpu-memory-buffer --lang=en-US --device-scale-factor=1 --num-raster-threads=4 --enable-main-frame-before-activation --renderer-client-id=6 --time-ticks-at-unix-epoch=-1731276721788615 --launch-time-ticks=76854660486 --field-trial-handle=3720,i,5630800143355803134,17034278787814789559,262144 --variations-seed-version --enable-logging=handle --log-file=3748 --mojo-platform-channel-handle=3736 /prefetch:1
- 20:32:56.000 DEBUG: Command line string for the renderer process: "C:\Users\cz\phpdesktop\phpdesktop\Release\phpdesktop-chrome.exe" --type=renderer --string-annotations=is-enterprise-managed=no --user-data-dir="C:\Users\cz\phpdesktop\phpdesktop\Release\webcache" --no-sandbox --remote-debugging-port=64095 --disable-gpu-compositing --video-capture-use-gpu-memory-buffer --lang=en-US --device-scale-factor=1 --num-raster-threads=4 --enable-main-frame-before-activation --renderer-client-id=5 --time-ticks-at-unix-epoch=-1731276721788615 --launch-time-ticks=76854664481 --field-trial-handle=3752,i,5630800143355803134,17034278787814789559,262144 --variations-seed-version --enable-logging=handle --log-file=3780 --mojo-platform-channel-handle=2052 /prefetch:1
[10364:17952:1111/203256.468:INFO:download_manager_delegate_impl.cc(360)] Rejected download of http://127.0.0.1:60064/download.php?getit=1
[10364:17952:1111/203256.469:INFO:download_manager_delegate_impl.cc(360)] Rejected download of http://127.0.0.1:60127/sqlite-database.db
[10364:17952:1111/203256.469:INFO:download_manager_delegate_impl.cc(360)] Rejected download of http://127.0.0.1:60340/download.php?getit=1
- 20:32:56.015 DEBUG: V8 browser was created
- 20:32:56.266 INFO: GET 200 /
- 20:32:56.266 INFO: GET 200 /style.css
- 20:32:56.062 DEBUG: V8 context created, in context: 1
- 20:32:56.282 DEBUG: OnLoadingStateChange: loading=0, url=http://127.0.0.1:55017/
- 20:32:56.313 INFO: GET 200 /favicon.ico
- 20:32:58.031 DEBUG: Command line string for the utility process: "C:\Users\cz\phpdesktop\phpdesktop\Release\phpdesktop-chrome.exe" --type=utility --utility-sub-type=chrome.mojom.ProcessorMetrics --lang=en-US --service-sandbox-type=none --no-sandbox --string-annotations=is-enterprise-managed=no --user-data-dir="C:\Users\cz\phpdesktop\phpdesktop\Release\webcache" --field-trial-handle=4392,i,5630800143355803134,17034278787814789559,262144 --variations-seed-version --enable-logging=handle --log-file=4456 --mojo-platform-channel-handle=4412 /prefetch:8
- 20:33:01.422 DEBUG: OnLoadingStateChange: loading=1, url=http://127.0.0.1:55017/
- 20:33:01.218 DEBUG: V8 browser was created
- 20:33:01.218 ERROR: StoreJavascriptApi() failed, api already exists
- 20:33:01.250 DEBUG: V8 context created, in context: 1
- 20:33:01.454 INFO: GET 200 /javascript-api.php
- 20:33:01.469 DEBUG: OnLoadingStateChange: loading=0, url=http://127.0.0.1:55017/javascript-api.php
- 20:33:01.500 INFO: GET 200 /favicon.ico
- 20:33:03.656 DEBUG: V8 execute phpdesktop object method: ToggleFullscreen
Available for hire. Projects: PHP Desktop, CEF Python and CEF C API. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1947
Joined: Sun Nov 06, 2011 2:12 am

Re: SendProcessMessage doesn't work when using stored browse

Postby Czarek » Mon Nov 11, 2024 2:42 pm

Hmm I see this line twice:
Code: Select all
DEBUG: V8 browser was created

Which means that CefRenderProcessHandler::OnBrowserCreated was called twice. Is it being called for each navigation within the same CEF browser?
Available for hire. Projects: PHP Desktop, CEF Python and CEF C API. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1947
Joined: Sun Nov 06, 2011 2:12 am

Re: SendProcessMessage doesn't work when using stored browse

Postby magreenblatt » Mon Nov 11, 2024 2:51 pm

A different renderer process will be used for cross-origin navigations. Possibly other navigations as well.
magreenblatt
Site Admin
 
Posts: 12974
Joined: Fri May 29, 2009 6:57 pm

Re: SendProcessMessage doesn't work when using stored browse

Postby ndesktop » Mon Nov 11, 2024 5:26 pm

You can use CefFrameHandler::OnFrameCreated/OnFrameAttached/OnFrameDetached to keep track of the browser and frame identifiers and compare with those used by the SendProcessMessage (browser and browser->GetMainFrame() identifiers) to be sure.
ndesktop
Master
 
Posts: 894
Joined: Thu Dec 03, 2015 10:10 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 55 guests