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.
There is a fatal bug in the doOnBeforePopup function
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: There is a fatal bug in the doOnBeforePopup function
Hi,
The default Result value in CEF for the OnBeforePopup callback is false to allow all popup windows.
However, you can override TChromium.doOnBeforePopup and add your customized code in a new component.
I modified the SimpleBrowser2 demo and set Result to true in the TChromium.OnBeforePopup event to test a few websites with popup windows.
SimpleBrowser2 blocked all popup windows correctly.
I'm not sure if this can be done in RAD Studio when you mix C++ and Delphi but if you can, set a breakpoint in TChromium.doOnBeforePopup to check that the Result parameter has the right value after the application executes TChromium.OnBeforePopup.
The default Result value in CEF for the OnBeforePopup callback is false to allow all popup windows.
However, you can override TChromium.doOnBeforePopup and add your customized code in a new component.
I modified the SimpleBrowser2 demo and set Result to true in the TChromium.OnBeforePopup event to test a few websites with popup windows.
SimpleBrowser2 blocked all popup windows correctly.
I'm not sure if this can be done in RAD Studio when you mix C++ and Delphi but if you can, set a breakpoint in TChromium.doOnBeforePopup to check that the Result parameter has the right value after the application executes TChromium.OnBeforePopup.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: There is a fatal bug in the doOnBeforePopup function
I forgot to add that the simpleBrowser2 demo disables NetworkService and OutOfBlinkCors with this code in the project file :
Try disabling NetworkService to see if the event is triggered as expected.
Code: Select all
GlobalCEFApp.DisableFeatures := 'NetworkService,OutOfBlinkCors';
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: There is a fatal bug in the doOnBeforePopup function
I went to "daum.net" and clicked all kind of links for more than 15 minutes but I didn't see any popup window.
I clicked on news articles, weather information, videos, maps, comics... I even clicked some ads but I didn't see any popup.
Perhaps the popup windows that you see contain ads that are targeted geographically by the IP and they only appear to users in your country.
Try using the TChromium.OnOpenUrlFromTab event too and set Result to true when targetDisposition is WOD_NEW_POPUP or WOD_NEW_WINDOW.
Please, let me know the URL of any website that shows popups even when you use TChromium.OnBeforePopup and TChromium.OnOpenUrlFromTab. All the information you could provide to reproduce this issue would be extremely helpful.
Edit: Now that I think of it, if the popup windows you see can be stopped by editing the default Result value in TChromium.doOnBeforePopup and the Delphi demos don't have that problem then it means that the Result value is not correctly passed from CEF4Delphi to C++ or from C++ to CEF4Delphi. Another person did a C++ builder port of CEF4Delphi long ago but he modified all the "var" parameters because he had problems with them.
I clicked on news articles, weather information, videos, maps, comics... I even clicked some ads but I didn't see any popup.
Perhaps the popup windows that you see contain ads that are targeted geographically by the IP and they only appear to users in your country.
Try using the TChromium.OnOpenUrlFromTab event too and set Result to true when targetDisposition is WOD_NEW_POPUP or WOD_NEW_WINDOW.
Please, let me know the URL of any website that shows popups even when you use TChromium.OnBeforePopup and TChromium.OnOpenUrlFromTab. All the information you could provide to reproduce this issue would be extremely helpful.
Edit: Now that I think of it, if the popup windows you see can be stopped by editing the default Result value in TChromium.doOnBeforePopup and the Delphi demos don't have that problem then it means that the Result value is not correctly passed from CEF4Delphi to C++ or from C++ to CEF4Delphi. Another person did a C++ builder port of CEF4Delphi long ago but he modified all the "var" parameters because he had problems with them.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: There is a fatal bug in the doOnBeforePopup function
I opened this URL using SimpleBrowser2 and MiniBrowser because SimpleBrowser2 blocks all popups but MiniBrowser allows all popups :
https://search.daum.net/search?w=tot&DA ... 5%EC%88%9C
MiniBrowser opened the popup window when I clicked that search result marked in red.
SimpleBrowser2 blocked the popup window when I clicked that search result marked in red.
I also tested https://www.daum.net/ and I clicked several ads with SimpleBrowser2 and MiniBrowser. MiniBrowser opened popup windows when I clicked the ads but SimpleBrowser2 blocked all of them.
I tested all this in Delphi 10.3 and Lazarus 2.0.2
Please, download the latest CEF4Delphi version and replace TChromium.doOnBeforePopup with this code in uCEFChromium.pas :
Enable the log in NinjaBrowser setting these properties :
Build CEF4Delphi and NinjaBrowser, navigate to the previous URL, click on the search result marked in red, close the browser and the open the debug.log file.
If you see a text line with "Result value : false" and you set Result to true inside NinjaBrowser then there's an issue passing a "var" parameter from C++ to CEF4Delphi.
https://search.daum.net/search?w=tot&DA ... 5%EC%88%9C
MiniBrowser opened the popup window when I clicked that search result marked in red.
SimpleBrowser2 blocked the popup window when I clicked that search result marked in red.
I also tested https://www.daum.net/ and I clicked several ads with SimpleBrowser2 and MiniBrowser. MiniBrowser opened popup windows when I clicked the ads but SimpleBrowser2 blocked all of them.
I tested all this in Delphi 10.3 and Lazarus 2.0.2
Please, download the latest CEF4Delphi version and replace TChromium.doOnBeforePopup with this code in uCEFChromium.pas :
Code: Select all
function TChromium.doOnBeforePopup(const browser : ICefBrowser;
const frame : ICefFrame;
const targetUrl : ustring;
const targetFrameName : ustring;
targetDisposition : TCefWindowOpenDisposition;
userGesture : Boolean;
const popupFeatures : TCefPopupFeatures;
var windowInfo : TCefWindowInfo;
var client : ICefClient;
var settings : TCefBrowserSettings;
var extra_info : ICefDictionaryValue;
var noJavascriptAccess : Boolean): Boolean;
begin
Result := False;
if Assigned(FOnBeforePopup) then
FOnBeforePopup(Self, browser, frame, targetUrl, targetFrameName,
targetDisposition, userGesture, popupFeatures, windowInfo, client,
settings, extra_info, noJavascriptAccess, Result);
CefDebugLog('Result value : ' + BoolToStr(Result, true));
end;
Code: Select all
GlobalCEFApp.LogFile := 'debug.log';
GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
If you see a text line with "Result value : false" and you set Result to true inside NinjaBrowser then there's an issue passing a "var" parameter from C++ to CEF4Delphi.
Re: There is a fatal bug in the doOnBeforePopup function
Tell me how to create a popup window programmatically without js
Chrom.CreateClientHandler
or how to raise the BeforePopap event
Chrom.CreateClientHandler
or how to raise the BeforePopap event
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: There is a fatal bug in the doOnBeforePopup function
There are 2 demos that show how to use custom popup windows :
- Delphi_VCL\PopupBrowser : Uses a browser in OSR mode.
- Delphi_VCL\PopupBrowser2 : Uses a browser in normal mode.
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: There is a fatal bug in the doOnBeforePopup function
If you mean to create a browser in a child form of your application you can use the code in the ToolBoxBrowser demo.
Re: There is a fatal bug in the doOnBeforePopup function
Code: Select all
function TMainForm.CreateClientHandler(var windowInfo : TCefWindowInfo;
var client : ICefClient;
const targetFrameName : string;
const popupFeatures : TCefPopupFeatures) : boolean;
begin
try
FCriticalSection.Acquire;
Result := (FChildForm <> nil) and
FChildForm.CreateClientHandler(windowInfo, client, targetFrameName, popupFeatures) and
PostMessage(Handle, CEF_CREATENEXTCHILD, 0, 0);
finally
FCriticalSection.Release;
end;
end;
This code raises the Chromium1BeforePopup event, but how to trigger this event itself so that all the parameters are available. while I see only one option is to call window.open with js
Re: There is a fatal bug in the doOnBeforePopup function
Code: Select all
Chromium1.LoadURL();
- salvadordf
- Posts: 4564
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: There is a fatal bug in the doOnBeforePopup function
If I remember correctly there are only 2 ways to trigger that event :
- Executing "window.open()" in JavaScript.
- Clicking on a HTML link which has a "_blank" target : "<a href='http://www.example.com' target='_blank'>click here to open a new tab or window</a>"