Recent

Author Topic: Webbrowser demo (Windows)  (Read 17124 times)

Timewarp

  • Full Member
  • ***
  • Posts: 144
Webbrowser demo (Windows)
« on: January 11, 2013, 10:25:03 am »
Created small tabbed webbrowser for Windows. It's based on IE / activexcontainer.pas

Screencap: http://i.imgur.com/RYRlb.jpg

Download: http://netikka.net/dev/LazBrowserDemo.zip
(could not attach, because of size)

Demo shows (for example) how to:

- Create tabbed browser
- Keyboard hook to capture key presses
- Mouse hook to capture mouse events
- Addressbar autocomplete (shlwapi)
- Read/write typed urls to registry
- Don't show Javascript errors
- Make tab key, F5, zooming work..
- Run webbrowsercontrol in IE8/9/10 mode
- Disable navigation sounds
- Disable activex / javascript / change other downloadoptions
- Disable scripts from specific domain/url(s)
- Redirect xxx to yyy using Translateurl
- Clear IE cache
- Use own useragent
- ...

It's cut from my larger Delphi project, not sure if I removed all useless code?!   

You can do whatever you like with it..

FPC 2.6.1 or later is needed. I have tested only latest 2.7.1. (for 64bit Lazarus FPC 2.7.1 compiled with -dTEST_WIN64_SEH is needed)

Timewarp

  • Full Member
  • ***
  • Posts: 144
Re: Webbrowser demo (Windows)
« Reply #1 on: June 28, 2013, 08:50:43 am »
Demo should work Lazarus 1.0.10 win32 (64bit Lazarus needs FPC2.7.1)

dcminus

  • New Member
  • *
  • Posts: 24
Re: Webbrowser demo (Windows)
« Reply #2 on: August 27, 2013, 04:31:50 pm »
Hi TimeWarp,

great example, worked great for my project. Thanks for publishing it. I started to rewrite my delphi app and got stuck here:

I need to get the current source from the WebBrowser which I did like this:
Code: [Select]
procedure TForm1.WBDocumentComplete(ASender: TObject; pDisp: IDispatch; var URL: OleVariant);
var r: integer;
 s: string;
 WB: TEvsWebBrowser;
 source: string;
iall: IHTMLElement;
begin
 WB:=TEvsWebBrowser(Asender);
 
  if Pos('analysis/analysis_main.asp',URL) > 0 then
    with WB.ComServer do
      begin
      if Assigned(document) then
      begin
         iall := (document AS IHTMLDocument2).Body;

         while iall.parentElement <> nil do
         begin
            iall := iall.parentElement;
         end;
         source := iall.outterHTML;
      end;
       FormDebug.Memo.Lines.Text:=source;
      ShowMessage('Done');
      end;

The source I get is not the one belongs to "analysis_main.asp" but the parent html of that.

Could you be so kind and tell me what did I do wrong?

Thanks in advance,

DC
« Last Edit: August 27, 2013, 04:50:27 pm by dcminus »

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: Webbrowser demo (Windows)
« Reply #3 on: August 28, 2013, 12:16:16 pm »
typo?: iall.outterHTML -> iall.outerHTML;

And don't use the "with" keyword, at least when debugging, it is confusing.

Timewarp

  • Full Member
  • ***
  • Posts: 144
Re: Webbrowser demo (Windows)
« Reply #4 on: August 31, 2013, 02:48:54 pm »
What is the url?

Documentcomplete can fire many times (if there are frames for example) You most likely want to keep this line anyway.

if (pDisp as IWebBrowser)<>WB.comserver then exit;

Just one thing I discovered recently. It's better to set browser emulation registry key in initialization section. This way it affects immediately, not just after next run.

dcminus

  • New Member
  • *
  • Posts: 24
Re: Webbrowser demo (Windows)
« Reply #5 on: September 17, 2013, 10:46:15 pm »
I had changed the url and inserted my if statement before

Code: [Select]
if (pDisp as IWebBrowser)<>WB.comserver then exit;
also it is 
Code: [Select]
iall.outerHTML;

Now I have a new question to you:

1. How can I get CTRL+C, CTRL+V, CTRL+X, CTRL+Z working on my tabs?


2. I would need to move some functions from my Delhi code and I can not figure out why they do not work:

Code: [Select]
function TickCheckBox(WebBrowser: TWebBrowser;
  tagName, TagType, TagValue: string): Boolean;
var
  ovElements: OleVariant;
  I: Integer;
begin
  ovElements := WebBrowser.OleObject.document.Forms.Item(0).Elements;
  for I := 0 to (ovElements.Length - 1) do
    if (ovElements.Item(I).tagName = tagName) and
      (ovElements.Item(I).type = TagType) and
      (ovElements.Item(I).value = TagValue) then
    begin
      // ovElements.item(i).Click;
      ovElements.Item(I).checked := True;
      Result := True;
    end;
end;


Thanks for your help,

DC

dcminus

  • New Member
  • *
  • Posts: 24
Re: Webbrowser demo (Windows)
« Reply #6 on: September 18, 2013, 12:14:41 am »
Ok I think I sorted the number 2, i used a slightly different function i had, I share just in case someone would need something like this:

Code: [Select]
function TickCheckBox(iDoc1: IHTMLDocument2;   tagName, tagType, tagValue: string): Boolean;
var
  WebForm: IHTMLFormElement;
  FormElements: olevariant;
  I: integer;
begin
  if Assigned(iDoc1) then
  begin
    WebForm := iDoc1.Forms.Item(0, '') as IHTMLFormElement;
    FormElements := WebForm.Elements;

    for I := 0 to FormElements.Length - 1 do
    begin
      if (FormElements.Item(I).tagName = tagName) and
         (FormElements.Item(I).getAttribute('type') = tagType) and
         (FormElements.Item(I).value = tagValue)
      then
        begin
          FormElements.Item(I).checked := True;
          Result:=True;
        end;
    end;
  end;
end;

for some reason this wont work (it works in delphi):

Code: [Select]
(FormElements.Item(I).type = tagType)
but this does:

Code: [Select]
(FormElements.Item(I).getAttribute('type') = tagType)
Cheers,

DC

dcminus

  • New Member
  • *
  • Posts: 24
Re: Webbrowser demo (Windows)
« Reply #7 on: September 18, 2013, 03:05:55 am »
and for the no. 1 need to add the following lines in: procedure TForm1.Timer2Timer(Sender: TObject);


Code: [Select]
var
  vaIn, vaOut: olevariant;   


Code: [Select]


    if event = 9 then
    begin
      (TLazBrowser(PageControl1.ActivePage.Controls[0]).ComServer as
    IWebbrowser2).ExecWB (OLECMDID_PASTE, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
    end;
    if event = 10 then
    begin
      (TLazBrowser(PageControl1.ActivePage.Controls[0]).ComServer as
    IWebbrowser2).ExecWB (OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
    end;
    if event = 11 then
    begin
      (TLazBrowser(PageControl1.ActivePage.Controls[0]).ComServer as
    IWebbrowser2).ExecWB (OLECMDID_CUT, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
    end;
    if event = 12 then
    begin
      (TLazBrowser(PageControl1.ActivePage.Controls[0]).ComServer as
    IWebbrowser2).ExecWB (OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
    end;


and these lines in function KeyboardHookProc(Code, wParam, lParam: longint): longint; stdcall;

Code: [Select]
      if wParam = Ord('V') then
      begin
        Result := 1;
        form1.handle_event := 9;
        form1.timer2.Enabled := True;
        exit; // Paste
      end;
      if wParam = Ord('C') then
      begin
        Result := 1;
        form1.handle_event := 10;
        form1.timer2.Enabled := True;
        exit; // Copy
      end;
      if wParam = Ord('X') then
      begin
        Result := 1;
        form1.handle_event := 11;
        form1.timer2.Enabled := True;
        exit; // Cut
      end;
      if wParam = Ord('A') then
      begin
        Result := 1;
        form1.handle_event := 12;
        form1.timer2.Enabled := True;
        exit; // Select All
      end;

Cheers

Timewarp

  • Full Member
  • ***
  • Posts: 144
Re: Webbrowser demo (Windows)
« Reply #8 on: September 18, 2013, 08:32:52 am »
".type" can be replaced with ".&type". (There is issue in bugtracker)

Code: [Select]
if (wParam=VK_TAB) or (wParam=VK_F5)
Adding
Code: [Select]
or ((GetKeyState(VK_CONTROL)<0) and (wParam = Ord('C'))) makes CTRL+C work.

I don't know why this is needed. Maybe should be handed somehow in activexcontainer.pas

dcminus

  • New Member
  • *
  • Posts: 24
Re: Webbrowser demo (Windows)
« Reply #9 on: September 19, 2013, 04:07:30 pm »
Code: [Select]
&type is still nicer :)

I realised when DEL pressed the following event "steals" DEL button pressed on webbrowser, here is an attempt fix it:

Code: [Select]
    if event = 13 then
    begin
      (TLazBrowser(PageControl1.ActivePage.Controls[0]).ComServer as
    IWebbrowser2).ExecWB (OLECMDID_DELETE, OLECMDEXECOPT_DODEFAULT, vaIn, vaOut);
    end;


Code: [Select]
    if wParam = VK_DELETE then
    begin
     if (form1.Ieaddress1.DroppedDown) and (form1.Ieaddress1.ItemIndex <> -1) then
      begin
        Result := 1;
        form1.handle_event := 8;
        form1.timer2.Enabled := True;
        exit; // Delete url
      end
     else
      begin
        Result := 1;
        form1.handle_event := 13;
        form1.timer2.Enabled := True;
        exit; // Copy
      end;
  end;
 

 8)

dcminus

  • New Member
  • *
  • Posts: 24
Re: Webbrowser demo (Windows)
« Reply #10 on: September 19, 2013, 06:31:35 pm »
How do i sort out BACKSPACE, same action as IE, so if i am inside a form delete to left,otherwise do a Webbrowser.goback?

Cheers,


uli65

  • New Member
  • *
  • Posts: 13
Re: Webbrowser demo (Windows)
« Reply #11 on: June 08, 2021, 05:54:27 pm »
Hello,

the link http://netikka.net/dev/LazBrowserDemo.zip seems dead?! Does anyone have the file LazBrowserDemo.zip and could provide it?

Thanks!

Uli65
Lazarus 2.0.6, FPC 3.0.4, Unidac 8.12

devEric69

  • Hero Member
  • *****
  • Posts: 520
Re: Webbrowser demo (Windows)
« Reply #12 on: June 09, 2021, 10:35:05 am »
Hello @uli65,

It's based on IE / activexcontainer.pas
- Run webbrowsercontrol in IE8/9/10 mode
...\...
- Clear IE cache
...\... should be handed somehow in activexcontainer.pas.
...\... same action as IE.

For information, Internet Explorer has been pronounced dead by Microsoft: "...the 25-year-old browser will disappear from the web on August 17, 2021: end of support. Microsoft will focus only on Microsoft Edge".
So, you maybe should rather look elsewhere (Mozilla, ...).
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

PascalDragon

  • Hero Member
  • *****
  • Posts: 3207
  • Compiler Developer
Re: Webbrowser demo (Windows)
« Reply #13 on: June 09, 2021, 01:49:45 pm »
So, you maybe should rather look elsewhere (Mozilla, ...).

While IE is definitely deprecated I doubt that the engine itself will disappear simply because so many applications depend on it. I wouldn't start any new projects with it however...

 

TinyPortal © 2005-2018