Webbrowser demo (Windows) lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Timewarp · 2013-01-11 09:25 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 · 2013-06-28 06:50 Demo should work Lazarus 1.0.10 win32 (64bit Lazarus needs FPC2.7.1) ---------------------------------------------------------------------- dcminus · 2013-08-27 14:31 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 ---------------------------------------------------------------------- theo · 2013-08-28 10:16 typo?: iall.outterHTML -> iall.outerHTML; And don't use the "with" keyword, at least when debugging, it is confusing. ---------------------------------------------------------------------- Timewarp · 2013-08-31 12:48 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 · 2013-09-17 20:46 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 · 2013-09-17 22:14 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 · 2013-09-18 01:05 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 · 2013-09-18 06:32 ".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 · 2013-09-19 14:07 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; ---------------------------------------------------------------------- dcminus · 2013-09-19 16:31 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 · 2021-06-08 15:54 Hello, the link http://netikka.net/dev/LazBrowserDemo.zip seems dead?! Does anyone have the file LazBrowserDemo.zip and could provide it? Thanks! Uli65 ---------------------------------------------------------------------- devEric69 · 2021-06-09 08:35 Hello @uli65, Quote from: Timewarp on January 11, 2013, 10:25:03 amIt'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, ...). ---------------------------------------------------------------------- PascalDragon · 2021-06-09 11:49 Quote from: devEric69 on June 09, 2021, 10:35:05 amSo, 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...