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.

Chromium.LoadRequest and Request.SetReferrer

Post Reply
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Chromium.LoadRequest and Request.SetReferrer

Post by igor666 »

Hi, there was a problem with requests in cef 78. In the BeforeResourceLoad event when setting the referrer with request.setreferrer on the loaded page, java does not see this referrer. It is visible in the request header, but the document.referer script produces an empty string. If you load the request using Cromium.LoadRequest, the referrer is visible both in the header and the Java script, but the problem is different here, LoadRequest does not work if the page was not loaded into the browser using LoadURL before. Even if the page was loaded and it made several transitions after returning (GoBack) LoadRequest also does not work, it does not load the page, just a white screen and debugger gives the error "Terminating renderer for bad IPC message".
How to set the referrer correctly so that it can be seen by the Java script or how to use Cromium.LoadRequest without fear that the call to this procedure will be after GoBack, LoadURL ('about: blank') (in this situation, LoadRequest also does not work) or after LoadString ?
User avatar
salvadordf
Posts: 4572
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Chromium.LoadRequest and Request.SetReferrer

Post by salvadordf »

Hi,

The original LoadString was removed from the CEF API because it wasn't working as expected.
I later added a LoadString replacement that uses a DATA URL as a workaround but it's not exactly the same.

The LoadRequest method is also problematic and now you need to first navigate to the request URL using some other mechanism (LoadURL, link click, etc). Otherwise, it will fail with “bad IPC message”.

Read this link for more information about the removal of LoadString :
https://bitbucket.org/chromiumembedded/ ... g-renderer

This forum thread might be interesting for you. The original poster abandoned LoadRequest and now he uses LoadURL :
https://www.magpcss.org/ceforum/viewtop ... 92&p=41093
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Re: Chromium.LoadRequest and Request.SetReferrer

Post by igor666 »

Unfortunately, the last post does not solve the problem. I install the referrer exactly through exactly as indicated in the post and such a referrer does not see the Java script. It is substituted into the request headers, but as I wrote above document.referrer is empty. I also wanted to switch to LoadURL, but the situation is hopeless, LoadRequest does not work, as it was in versions 45 and 49, and LoadURL does not install a referrer.
Maybe we can somehow programmatically create a renderer like when calling LoadURL to use LoadRequest as before?
P.S. Maybe instead of LoadURL we can use LoadResource before LoadRequest? I really still have not figured out how it works :).
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Re: Chromium.LoadRequest and Request.SetReferrer

Post by igor666 »

And another question is not on this topic. I have two TCromium components and two TCEFWindowParent components on which different pages are loaded. When I try to call ShowDevTools for the first Cromium, it works fine, when for the second, I get a "bad IPC message" error and there is a white window in the first. In version 45, everything worked fine. Can you tell me what could be the problem?
I'm sorry, I'm transferring the program from the old version of CEF to the new one, many functions have stopped working :).

I noticed an interesting behavior of the program, perhaps this is due precisely to the topic of the post and the second question. The bottom line is, as I wrote above, my program uses two Chrome components that are located horizontally on the same form. The top site loads the same site (there may be different pages), for example, www.my-site.com. At the bottom there may be pages of both the site www.my-site.com and any other site, for example, www.not-my-site.com. At the top we load my-site using LoadURL, at the bottom we load "my-site" too, but with the help of LoadRequest, everything works fine. Then we load "not-my-site" below with the help of LoadRequest and get "bad IPC message". If we load "not-my-site" below with LoadURL, it works as soon as LoadRequest, even after LoadURL, does not work.
When we have sites with the same domain loaded in both Chromium, everything is OK, even with LoadRequest. But when we start loading another domain into one of Chromium using LoadRequest we get an error.
User avatar
salvadordf
Posts: 4572
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Chromium.LoadRequest and Request.SetReferrer

Post by salvadordf »

igor666 wrote: Thu Dec 12, 2019 7:58 am And another question is not on this topic. I have two TCromium components and two TCEFWindowParent components on which different pages are loaded. When I try to call ShowDevTools for the first Cromium, it works fine, when for the second, I get a "bad IPC message" error and there is a white window in the first. In version 45, everything worked fine. Can you tell me what could be the problem?
I'm sorry, I'm transferring the program from the old version of CEF to the new one, many functions have stopped working :).
I tried that in BriskBard with the latest CEF binaries and I could open 2 DevTools in 2 tabs without problems.
BriskBard uses different TCEFWindowParent component to show the DevTools in each tab.
If you are using the same TCEFWindowParent component to show the DevTools for all the browsers then try using a new one for each browser.
igor666 wrote: Thu Dec 12, 2019 7:58 am I noticed an interesting behavior of the program, perhaps this is due precisely to the topic of the post and the second question. The bottom line is, as I wrote above, my program uses two Chrome components that are located horizontally on the same form. The top site loads the same site (there may be different pages), for example, www.my-site.com. At the bottom there may be pages of both the site www.my-site.com and any other site, for example, www.not-my-site.com. At the top we load my-site using LoadURL, at the bottom we load "my-site" too, but with the help of LoadRequest, everything works fine. Then we load "not-my-site" below with the help of LoadRequest and get "bad IPC message". If we load "not-my-site" below with LoadURL, it works as soon as LoadRequest, even after LoadURL, does not work.
When we have sites with the same domain loaded in both Chromium, everything is OK, even with LoadRequest. But when we start loading another domain into one of Chromium using LoadRequest we get an error.
These are the code comments in the CEF source code for the LoadRequest procedure :
https://bitbucket.org/chromiumembedded/ ... #lines-132

Code: Select all

  ///
  // Load the request represented by the |request| object.
  //
  // WARNING: This function will fail with "bad IPC message" reason
  // INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the request
  // origin using some other mechanism (LoadURL, link click, etc).
  ///
What you describe is a known issue in the CEF libraries and we can't do anything to avoid it for now.
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Re: Chromium.LoadRequest and Request.SetReferrer

Post by igor666 »

If you are using the same TCEFWindowParent component to show the DevTools for all the browsers then try using a new one for each browser.
This does not work in my case. Maybe due to the fact that I have 2 browsers not in tabs, but directly under each other on the form. Or maybe it's due to the migration from version 49 of Chrome to 78 some kind of bug in the project. I'll try to recreate the project again.
Thank you for your time. I will attach the screen, when loading the LoadURL () page and inserting the referrer in the onBeforeResourceLoad event with request.SetReferer (), this is the result. javascript_ref is document.referrer
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4572
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Chromium.LoadRequest and Request.SetReferrer

Post by salvadordf »

igor666 wrote: Fri Dec 13, 2019 7:15 am I will attach the screen, when loading the LoadURL () page and inserting the referrer in the onBeforeResourceLoad event with request.SetReferer (), this is the result. javascript_ref is document.referrer
If your application only needs to send a POST request and get the results perhaps the "URLRequest" demo could be used as an alternative to TChromium.LoadRequest.
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Re: Chromium.LoadRequest and Request.SetReferrer

Post by igor666 »

Yes, I also thought about it, but I need not only to get an answer, but also to display the page. Using URLRequest I didn’t succeed. Do not tell me how this can be done, if possible? Or maybe there are ideas how to use the LoadURL to substitute the referrer so that it is visible not only in the request headers, but also in the DOM of the page?
By the way, today I conducted several experiments with LoadRequest and found out that it works even after LoadURL only if the hosts match. For example, if you make LoadURL ('http://briskbard.com'), then LoadRequest will only work on the pages "briskbard.com / ..." and nothing more. Any other site will cause a "bad IPC message" error.
igor666
Posts: 68
Joined: Fri Feb 08, 2019 1:25 pm

Re: Chromium.LoadRequest and Request.SetReferrer

Post by igor666 »

Good day and thanks for your time. Understood with both problems. The setting GlobalCEFApp.DisableSiteIsolationTrials: = true helped with LoadRequest. After adding her requests began to work as it should without error "bad IPC message".
Well, with DevTools, my mistake was, I didn’t know that when I called DevTools, a URL like devtools: // ... was sent to the browser with all the handlers that came from there. And in my program in the onBeforeResourceLoad event url requests are processed and url data was processed incorrectly.
Thanks again :).
Post Reply