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.

Prevent login page to open new windows

Post Reply
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Prevent login page to open new windows

Post by salvadordf »

lifeform wrote: Sun Oct 21, 2018 7:54 am hello

my login page is used frame, i can login but when button login clicked it always open new windows and always open like that...

my code is like this
noFrame := message.ArgumentList.GetInt(1);
chrome.Browser.GetFrameByident(noFrame).ExecuteJavaScript('document.evaluate("' + input_email + '", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.value = ' + QuotedStr(username) + ';', 'about:blank', 0);
Application.ProcessMessages;
Sleep(250);
Application.ProcessMessages;
chrome1.Browser.GetFrameByident(noFrame).ExecuteJavaScript('document.evaluate("' + input_password + '", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.value = ' + QuotedStr(password) + ';', 'about:blank', 0);
Application.ProcessMessages;
Sleep(250);
Application.ProcessMessages;
chrome1.Browser.GetFrameByident(noFrame).ExecuteJavaScript('document.evaluate("' + button_login_inframe + '", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();', 'about:blank', 0);


where noFrame is identification of the frame where login form located.

is there something wrong with my code?

i also have prevent popup with event before popup
Set a breakpoint in the TChromium.OnBeforePopup event to check if it's triggered. If not, delete it and add it again by double clicking in the "Object Inspector" in Delphi.

Some old CEF4Delphi versions had slightly different TChromium.OnBeforePopup event parameters and this could break that event.

I would advise against using "Application.ProcessMessages". Read this for more information about it :
https://stackoverflow.com/questions/251 ... i-is-doing
https://www.thoughtco.com/dark-side-of- ... es-1058203
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Prevent login page to open new windows

Post by salvadordf »

lifeform wrote: Sun Oct 21, 2018 11:14 am hello,
how to force chrome to show some change after i execute javascript without call processmessage?
i use processmessage to show some javascript action and click it.
If you need to send information or events from JavaScript to Delphi you have to send messages between processes.
You can use the CEF3 functions, a third party IPC library or websockets.
lifeform wrote: Sun Oct 21, 2018 11:14 am back to real problem
with the source i gave before and without block popup, i can login to my page. but it show popup and infinite popup show up until i force close it.
but after i open my site again. i already login.
if i gave block popup, the site is not responding. click is not responding. could you help gave some clue here
lifeform wrote: Sun Oct 21, 2018 12:01 pm how about...
how to force popup windows to processed in the main windows?
This forum post explains how to open popups in the same browser :
https://www.briskbard.com/forum/viewtop ... 577&p=2570
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Prevent login page to open new windows

Post by salvadordf »

lifeform wrote: Sun Oct 21, 2018 12:36 pm
If you need to send information or events from JavaScript to Delphi you have to send messages between processes.
You can use the CEF3 functions, a third party IPC library or websockets.
i do not know what you want to explain. but i adopt from your demo about javascript and it is working
I'm sorry. Now I see that you meant Application.ProcessMessages.

You can split your previous code in 3 procedures. One procedure for each "ExecuteJavaScript" call.

Then you can use a TTimer to execute those 3 procedures.
The first timer tick would execute the first procedure which has the first "ExecuteJavaScript" call.
The second timer tick would execute the second procedure with the second "ExecuteJavaScript" call.
The last timer tick would execute the last procedure and then you can disable the timer.
lifeform wrote: Sun Oct 21, 2018 12:36 pm
This forum post explains how to open popups in the same browser :
https://www.briskbard.com/forum/viewtop ... 577&p=2570
i tried first method and it cannot working.
the second method where i can get WindowInfoAsChild working?
om event before_popup? how to call it. sorry... really blank here
I posted that code too quickly. I'll test it and I'll post it here.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Prevent login page to open new windows

Post by salvadordf »

After some tests I realized that the current CEF4Delphi structure and the latest CEF3 binaries can't open popup windows in the same browser unless you block the new popup window and call TChromium.LoadURL.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Prevent login page to open new windows

Post by salvadordf »

Create a variable called "timer_counter" in your form to count how many times TTimer.OnTimer is executed and set it to 0 when the form is created.

Then add the TTimer.OnTimer event to your form :

Code: Select all

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  case timer_counter of
    0 :
      begin
        // call the first ExecuteJavaScript here
        inc(timer_counter);
      end;
      
    1 :  
      begin
        // call the second ExecuteJavaScript here
        inc(timer_counter);
      end;    
      
    2 :  
      begin
        // call the third ExecuteJavaScript here
        Timer1.Enabled := False; // This is the last ExecuteJavaScript and now the timer must be disabled
      end;      
  end;
end; 
Post Reply