Recent

Author Topic: Ole based browser fails on second .Navigate  (Read 3155 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 416
Ole based browser fails on second .Navigate
« on: August 27, 2021, 08:14:36 pm »
Platform:  Laz 2.0.10  FPC  3.2.0  Windows Server 2016 (all updates)

Background:  I need to launch InternetExplorer and have it navigate to a website. In this case NetCare, a well known health information website for physicians in Alberta Canada.  I was trying to do this with ActiveX but IE has moved on since the ActiveX example for Lazarus was made, and the imported TLB doesn't match the example anymore.  I am unable to get it to work.  So I used Ole instead. (BTW, I built this exact thing in Delphi and it worked great for many years, using the TWebBrowser component in Delphi.  (I say this just to confirm that the goal is achievable, not to "trash" Lazarus.  I'm a Lazarus fan.)(Also, I am unable to convert TWebBrowser from Delphi, as some have suggested.)

Problem:  The below source code works.... "sort of".  It will only do one Navigate, the first one.  After that, subsequent .Navigate calls fail, and the user gets the message "RPC server disconnected".

Does anyone have a working example to do a Parameter Launched Browser session using Lazarus?  Specifically for NetCare, which uses Citrix.



Code: Pascal  [Select][+][-]
  1. unit f_netcare;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs; // , SHDocVw_1_1_TLB
  9.  
  10. type
  11.  
  12.   { TfrmNetCare }
  13.  
  14.   TfrmNetCare = class(TForm)
  15.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure FormDestroy(Sender: TObject);
  18.   private
  19.     //IEBrowser: TAxcWebBrowser;
  20.     Browser: OleVariant;
  21.     procedure LoadDefaults;
  22.     procedure LoadPersistent;
  23.  
  24.   public
  25.     procedure GoToClient(const pnt_uli: String);
  26.     procedure GoToURL(const url_str: String);
  27.   end;
  28.  
  29. implementation
  30.  
  31. uses Windows, ComObj, u_gv;
  32.  
  33. {$R *.lfm}
  34.  
  35. { TfrmNetCare }
  36.  
  37. procedure TfrmNetCare.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  38. begin
  39.   CloseAction := caHide;
  40. end;
  41.  
  42. procedure TfrmNetCare.FormCreate(Sender: TObject);
  43. begin
  44.   LoadDefaults;
  45.   LoadPersistent;
  46. end;
  47.  
  48. procedure TfrmNetCare.FormDestroy(Sender: TObject);
  49. begin
  50.   //GV.IEBrowser.Free;
  51.   Browser := Unassigned;
  52. end;
  53.  
  54. procedure TfrmNetCare.LoadDefaults;
  55. begin
  56.   //GV.IEBrowser := TAxcWebBrowser.Create(Self);
  57.   //GV.IEBrowser := TAxcWebBrowser.CreateParented(Handle);
  58.   //GV.IEBrowser.OleServer.Visible := True;
  59.   //GV.IEBrowser.OleServer.ToolBar := False;
  60.   //GV.IEBrowser.OleServer.ShowBrowserBar();
  61.   //GV.IEBrowser.OleServer.FullScreen := False;
  62.  
  63.   try
  64.     Browser := CreateOleObject('InternetExplorer.Application');
  65.     Windows.SetParent(Browser.hwnd, Self.Handle);
  66.  
  67.     Browser.Toolbar := False;
  68.     Browser.Fullscreen := True;
  69.     //Browser.Resizable := False;
  70.     Browser.Visible := True;
  71.   except
  72.     on E: Exception do
  73.       begin
  74.         if SameText(E.ClassName, 'EOleSysError') then
  75.           begin
  76.             GV.NetCare.OLE_Blocked := True;
  77.             //ShowMessage('It appears that a previous copy of this app was unable to release the Browser.OleObject.  This means that this instance of this app will not be able to call NetCare.  Instead, you can use NetCare in tne other open instance of RUBI, or, use click/copy of Client Billing ID numbers from this app and paste into NetCare manually.');
  78.           end;
  79.       end;
  80.   end;
  81.  
  82. end;
  83.  
  84. procedure TfrmNetCare.LoadPersistent;
  85. begin
  86.   //
  87. end;
  88.  
  89. procedure TfrmNetCare.GoToClient(const pnt_uli: String);
  90. var go2url: String;
  91. begin
  92.   GV.NetCare.was_used := True;
  93.   go2url := StringReplace(GV.NetCare.BaseURL, '[LOGIN_ID]', GV.UsrProps.netcare_login_id, []);
  94.   go2url := StringReplace(go2url, '[AHC_ID]', pnt_uli, []);
  95.   GoToURL(go2url);
  96. end;
  97.  
  98. procedure TfrmNetCare.GoToURL(const url_str: String);
  99. var
  100.   w_url_str: WideString;
  101.   ole_url, ole_null: Olevariant;
  102. begin
  103.   w_url_str := url_str;
  104.   Browser.Silent := True;
  105.   Browser.Navigate(w_url_str, null, null, null, null);
  106.   Show;
  107.   BringToFront;
  108. end;
  109.  
  110. end.
  111.  

winni

  • Hero Member
  • *****
  • Posts: 2709
Re: Ole based browser fails on second .Navigate
« Reply #1 on: August 27, 2021, 09:07:47 pm »
Hi!

Read the old news from Microsoft:

______________________________

Important

The Internet Explorer 11 desktop application will be retired and go out of support on June 15, 2022 (for a list of what's in scope, see the FAQ). The same IE11 apps and sites you use today can open in Microsoft Edge with Internet Explorer mode. Learn more here.
_______________________________


From https://docs.microsoft.com/en-us/troubleshoot/browsers/only-secure-content-is-displayed-message


You can integrate the Chromium web browser in your Lazarus project:

https://forum.lazarus.freepascal.org/index.php/topic,55287.msg411329.html#msg411329



Winni

Soner

  • Sr. Member
  • ****
  • Posts: 253
Re: Ole based browser fails on second .Navigate
« Reply #2 on: August 27, 2021, 10:43:07 pm »
Use the function OpenURL form the unit lclintf. It is crossplatform.

Or when you still want use Internet Explorer then look at my example code.
It compiles on Lazarus and Delphi 7 and Delphi 2006 tested.
Also you can enable and disable some functions, look at the code.

Also look at this  topic. I posted there similiar code.
« Last Edit: August 27, 2021, 10:51:46 pm by Soner »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1053
Re: Ole based browser fails on second .Navigate
« Reply #3 on: August 28, 2021, 01:34:18 pm »
hello,
Platform:  Laz 2.0.10  FPC  3.2.0  Windows Server 2016 (all updates)
Background:  I need to launch InternetExplorer and have it navigate to a website. In this case NetCare, a well known health information website for physicians in Alberta Canada. 
to automate a browser to get informations from a website you can use selenium. With selenium you can use chrome , edge chromium, firefox as automating browser.
for lazarus you can try to use Webdriver4L (not all selenium functions , not tested with edge) :
Quote
WebDriver4L   Selenium Webdriver for Lazarus   // Jurassic Pork 01/2021
Derivative work from Ericwang1104/WebDriver4D  : https://github.com/Ericwang1104/WebDriver4D
Source code modified to use fphttpclient, fpjson,jsonparser.
The project is in alpha stage.
A demo project is included :  get a screenshot of the lazarus forum, get all the recent topics and display then in a memo, get stats.
the demo project has been tested on windows 10 lazarus 2.0.10   with chrome browser and on Ubuntu 20.04 Lazarus 2.0.10 with firefox browser.
You must download the selenium Webdriver for your browser and put it in your project folder. You must use a compatible driver version of your browser :
For Chrome the selenium drivers are here : https://chromedriver.chromium.org/downloads
For Firefox the selenium drivers are here : https://github.com/mozilla/geckodriver/releases
For example if you use Chrome 92.X on Windows  download a 92  version of the driver.

The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders X be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software.

Ericwang1104/WebDriver4D has no license so this project will not be published on github. No activity since March 2019

Friendly, J.P
« Last Edit: August 28, 2021, 01:38:15 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

PascalDragon

  • Hero Member
  • *****
  • Posts: 3406
  • Compiler Developer
Re: Ole based browser fails on second .Navigate
« Reply #4 on: August 28, 2021, 02:15:20 pm »
Does anyone have a working example to do a Parameter Launched Browser session using Lazarus?  Specifically for NetCare, which uses Citrix.

I don't have an example which uses parameters, but I've attached a simple browser that uses an Edit and a Button to trigger the navigation and that works here at least on Windows 10 21H1 (Build 19043.1165).

Can you maybe provide a self contained example that shows your problem?

RedOctober

  • Sr. Member
  • ****
  • Posts: 416
Re: Ole based browser fails on second .Navigate
« Reply #5 on: August 30, 2021, 05:14:20 pm »
Hi PascalDragon,  thanks for your help.

I'm beginning to think there is a difference between the IE on Windows Server 2016 and the IE on Windows 10.  Your demo starts a browser, but it is only partially functional.  The loaded page always has something missing.  Either the text of the page is missing and only the images show up, or, there is only shadow outlines of the images and text blocks, and nothing else. 

UPDATE:  I read this message before winnie 's message above. The secure content issue is what is probably causing this.

Out of curiosity, I added the following line to your example (at the Button1Click):

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var  ThisBrowser: OleVariant;
  3. begin
  4.   ThisBrowser := GetActiveOleObject('InternetExplorer.Application');
  5. ...
  6.  


The same error occurs.  I will now have a look at Selenium.

Project iebrowser raised exception class 'EOleSysError' with message:
Operation unavailable

 At address 10019801F


« Last Edit: August 30, 2021, 05:24:18 pm by RedOctober »

RedOctober

  • Sr. Member
  • ****
  • Posts: 416
Re: Ole based browser fails on second .Navigate
« Reply #6 on: August 30, 2021, 05:17:44 pm »
Hi Soner,  thanks for your help.

I have used OpenURL before, to open a web page.  But my understanding is that OpenURL will always open a new browser (or new tab in an open browser).  I can't have that for NetCare.  The existing browser session must be opened at a new page, not a new one created.  Am I wrong?  Will OpenURL open an existing browser, existing tab, to the new URL fed to it?

I will experiment with it.

UPDATE:   OpenURL always opens an additional new tab in a browser.   It would be amazing if OpenURL() had a parameter that you could feed it that wd tell it to navigate the existing focused tab to a new URL. That wd solve my problem.
« Last Edit: August 30, 2021, 05:22:01 pm by RedOctober »

winni

  • Hero Member
  • *****
  • Posts: 2709
Re: Ole based browser fails on second .Navigate
« Reply #7 on: August 30, 2021, 09:42:43 pm »
Hi!

The windows version of OpenURL calls finally Shellexecute which does not know anything about tabs. It searches the default browser and passes the URL to the browser.

Now it is up to the browser what happens.

I dont have an idea how to control that.

Winni

winni

  • Hero Member
  • *****
  • Posts: 2709
Re: Ole based browser fails on second .Navigate
« Reply #8 on: August 30, 2021, 09:52:20 pm »
Ha - you are not alone.

Firefox seems to support "always use the same tab"

The Mozilla support says:

Code: Text  [Select][+][-]
  1. To make Firefox open all links in the same tab, follow these instructions:
  2.  
  3.     Type about:config in the Firefox address bar
  4.     Bypass the security warning
  5.     Find the browser.link.open_newwindow.restriction preference
  6.     Double click it to change the value to 0
  7.     Find the browser.link.open_newwindow preference
  8.     Double click it to change the value to 1


From : https://support.mozilla.org/en-US/questions/1226151

Dont know if that works

Winni

loaded

  • Sr. Member
  • ****
  • Posts: 308
Re: Ole based browser fails on second .Navigate
« Reply #9 on: August 31, 2021, 01:22:17 am »
In my opinion, the browser beast CEF3 or using CEF4Delphi it's time
Lazarus V2.0.10 32 Bit + Intel I5 8250U + 12GB RAM + Win 10 Home 64 Bit = red pill
Morpheus: "You take the blue pill...the story ends, you wake up in your bed and believe whatever you want to believe. You take the red pill...you stay in Wonderland, and I show you how deep the rabbit hole goes."

 

TinyPortal © 2005-2018