'TWebbrowser / TEmbeddedWb : hide all messageboxes

I have an application that uses TEmbeddedWb to automate data scrapping tasks.

Some web-sites show messages / popup boxes when my app navigates to it, and these makes the process slower.

I want to block any messagebox that TWebbrowser could show.

I'm already setting the 'silent' property to true, and also setting the onshowmessage method as follow, but still the messageboxes are show. Any hints ?

 function TForm1.webShowMessage(Sender: TObject; HWND: Cardinal; lpstrText,
 lpstrCaption: PWideChar; dwType: Integer; lpstrHelpFile: PWideChar; dwHelpContext: Integer;
 var plResult: Integer): HRESULT;
 begin
 plresult := S_OK;
 end;


Solution 1:[1]

I could achieve these task by making some changes on TEmbeddedWb source, specifically on the functionbelow :

 procedure TEmbeddedWB.HandleDialogBoxes(var AMsg: Messages.TMessage);

Here is the change :

 DlgClss := GetWinClass(PopHandle);
 WinClss := GetWinClass(Windows.GetParent(PopHandle));
 DlgCaption := GetWinText(PopHandle);
 if (DlgClss = 'Internet Explorer_TridentDlgFrame') or ((DlgClss = '#32770'))
   // comment here to make all windows be evaluated
   {and (WinClss <> 'TApplication') and
   (FindControl(Windows.GetParent(PopHandle)) = nil))}
   then
 begin
   if (WinClss = 'TApplication') or (FindControl(Windows.GetParent(PopHandle)) <> nil) then
     begin
     if pos('web browser',lowercase(DlgCaption)) = 0 then
       exit;
     end;

Solution 2:[2]

I just add this code Result := S_OK; on ShowMessage Event and no more popup message:

function TForm1.webShowMessage(Sender: TObject; HWND: Cardinal; lpstrText,
 lpstrCaption: PWideChar; dwType: Integer; lpstrHelpFile: PWideChar; dwHelpContext: Integer;
 var plResult: Integer): HRESULT;
 begin
 Result := S_OK;
 end;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 delphirules
Solution 2 Anthoner Monzon