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.
All the new TChromum events convert the JSON buffers encoded in UTF8 to an ICefValue instance automatically. They are in fact a ICefDictionaryValue instance with all the JSON information.
CEF allows you to modify the request in some events but not in others. For example, you can't modify the request in TChromium.OnBeforeBrowse but you can modify it in TChromium.OnBeforeResourceLoad.
If you're trying to use TChromium.LoadRequest you need to first navigate to the request origin using some other mechanism (LoadURL, link click, etc).
In BeforeResourceLoad
On each version I did not check but on CEF 75.1.14 there are no problems with this, I did not ask how to do it, but said that it stopped working.
procedure TMiniBrowserFrm.Chromium1BeforeResourceLoad(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const callback: ICefRequestCallback;
out Result: TCefReturnValue);
var
u: TUrlParts;
begin
if CefParseUrl(request.Url, u) then begin
if (Pos( 'briskbard.com/images/logo.', request.Url) <> 0) then begin // https://www.briskbard.com/index.php?lang=en
u.scheme:= 'https';
u.host := 'www.google.com';
u.origin := 'https://www.google.com/';
u.path := '/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png';
u.query := '';
request.Url := CefCreateUrl(u);
end;
end;
Result := RV_CONTINUE;
if Chromium1.IsSameBrowser(browser) and
(frame <> nil) and
frame.IsMain and
frame.IsValid then
InspectRequest(request);
end;
I would like to make a mistake that I am doing something wrong, but if you try it you will see that it does not work as before.
TUrlParts has a "spec" field and according to the CEF documentation means "The complete URL specification".
CefParseUrl had a bug and it didn't read the "spec" value but I fixed it months ago.
The variable "u" is used to parse the URL, then some of the fields are modified and then it's reused with CefCreateUrl. In that process "spec" is never rewritten and it keeps the old URL value... and CefCreateUrl prioritizes the "spec" value to generate the new URL.
There are 3 solutions :
Set the "spec" value with the new complete URL.
Set the "spec" value to an empty string.
Use a different TUrlParts variable with an empty "spec" to call CefCreateUrl.