Page 1 of 2
Re: There is a fatal bug in the doOnBeforePopup function
Posted: Tue Aug 06, 2019 8:29 am
by salvadordf
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.
Re: There is a fatal bug in the doOnBeforePopup function
Posted: Tue Aug 06, 2019 9:34 am
by salvadordf
I forgot to add that the simpleBrowser2 demo disables NetworkService and OutOfBlinkCors with this code in the project file :
Code: Select all
GlobalCEFApp.DisableFeatures := 'NetworkService,OutOfBlinkCors';
Try disabling NetworkService to see if the event is triggered as expected.
Re: There is a fatal bug in the doOnBeforePopup function
Posted: Tue Aug 06, 2019 1:11 pm
by salvadordf
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.
Re: There is a fatal bug in the doOnBeforePopup function
Posted: Tue Aug 06, 2019 7:19 pm
by salvadordf
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 :
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;
Enable the log in NinjaBrowser setting these properties :
Code: Select all
GlobalCEFApp.LogFile := 'debug.log';
GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
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.
Re: There is a fatal bug in the doOnBeforePopup function
Posted: Sun Apr 19, 2020 12:16 am
by dvbss11
Tell me how to create a popup window programmatically without js
Chrom.CreateClientHandler
or how to raise the BeforePopap event
Re: There is a fatal bug in the doOnBeforePopup function
Posted: Mon Apr 20, 2020 8:24 am
by salvadordf
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.
Additionally, you can let CEF create the popup windows but then you have to be prepared to handle the events of more than one browser with the same TChromium component. The MiniBrowser demo does this and many events check "Chromium1.IsSameBrowser(browser)" to see what browser triggered that event.
Re: There is a fatal bug in the doOnBeforePopup function
Posted: Mon Apr 20, 2020 8:58 am
by salvadordf
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
Posted: Mon Apr 27, 2020 11:41 pm
by dvbss11
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;
I am familiar with these demos but there isn’t such a thing. This code causes you to redirect the popup to a new form.
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
Posted: Mon Apr 27, 2020 11:45 pm
by dvbss11
this code opens a new page and how to open the same page as popap?
Re: There is a fatal bug in the doOnBeforePopup function
Posted: Tue Apr 28, 2020 8:25 am
by salvadordf
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>"