multithreading - Delphi - can't supress JavaScript error dialogs using IWebBrowser2 in a multi-threaded application -


this question has answer here:

i have app in delphi xe2 (runs on win7 x64, msie 10.0.9200.16635 installed), creates multiple threads. each thread creates iwebbrowser2 interface, navigates web page, saves disk, deletes iwebbrowser2 interface , terminates thread. "silent" property of web browser set true. problem urls these errors after terminating working thread (e.g. web browser should not exist anymore: screenshot1 screenshot2

these javascript errors, first 1 says "function expected", url res://ieframe.dll/preview.js, , other 1 "the callee (server [not server application]) not available , disappeared; connecitons invalid. call did not execute". url same, res://ieframe.dll/preview.js. need supress these error dialogs, can't. iwebbrowser2 not have "scripterrorssuppressed" property, can't go way. first message , other one. have spent 3 days looking answer , helpless. working threads job, have no memory leaks - problem these error dialogs. have disabled debugging , error messages in msie's advanced options, not help. think can happening here after thread , objects "officially" deleted, javascript page still being executed somewhere in memory. then, discovers browser object gone , that's why getting second message "the callee (server...".

here code:

    function atlaxattachcontrol(const pcontrol: iunknown;   hwnd: hwnd; ppunkcontainer: iunknown): dword; stdcall; external 'atl.dll';  procedure twpthread.execute; const   clsid_internetexplorer: tguid = '{8856f961-340a-11d0-a96b-00c04fd705a2}'; var   wndclass: twndclassex;   webbrowser: iwebbrowser2;   handle: hwnd;   msg:tmsg;   iall:ihtmlelement; begin   fillchar(wndclass, sizeof(wndclass), 0);   wndclass   begin     cbsize := sizeof(wndclass);     lpszclassname := 'message_only_window';     lpfnwndproc := @defwindowproc;   end;   registerclassex(wndclass);   handle := createwindowex(0, wndclass.lpszclassname, nil, 0, 0, 0, 0, 0, dword(hwnd_message), 0, 0, nil);   if (handle = 0) raise exception.create('createwindowex');   try    coinitializeex(nil, coinit_apartmentthreaded);    if (cocreateinstance(clsid_internetexplorer, nil, clsctx_inproc_server, iid_iwebbrowser2, webbrowser) <> s_ok) raise exception.create('cocreateinstance');    try     atlaxattachcontrol(webbrowser, handle, nil);     webbrowser.silent:=true;     webbrowser.navigate('http://investing.money.msn.com/investments/stock-report?cr=1&af=1&ih=1&aie=1&air=1&frh=1&frk=1&isa=1&isq=1&bsa=1&bsq=1&cfa=1&cfq=1&tys=1&itt=1&itp=1&type=equity&symbol=aan', emptyparam, emptyparam, emptyparam, emptyparam) ;     while (webbrowser.readystate <> readystate_complete)     begin      while peekmessage(msg, 0, 0, 0, pm_remove) dispatchmessage(msg);      sleep(1);     end;      // messageboxw(0, pwidechar((wb.document ihtmldocument2).title), '', 0);      iall := (webbrowser.document ihtmldocument2).body;      while iall.parentelement <> nil iall := iall.parentelement;      form1.memo1.text := iall.outerhtml;      form1.memo1.lines.savetofile('d:\memo.html');          webbrowser:=nil;     end;        destroywindow(handle);     couninitialize;   end; end;   procedure tform1.button1click(sender: tobject); begin  twpthread.create; end; 

what doing wrong? there method can prevent appearing these error dialogs? thinking injecting own javascript in downloaded page - e.g. own window.onerror handler supress error, not sure if correct way, , not javascript, code injecting stuff.

any appreciated, thank you! ace.

you can disable script debugger using registry additionally using "silent" property, in c# (code taken cswebbrowsersuppresserror). can done 1 time on start of application. take on @locster answer

var newvalue = value ? "yes" : "no";  using (registrykey iemainkey = registry.currentuser.opensubkey(      @"software\microsoft\internet explorer\main", true)) {      string keyvalue = iemainkey.getvalue("disable script debugger") string;      if (!keyvalue.equals(newvalue, stringcomparison.ordinalignorecase))      {          iemainkey.setvalue("disable script debugger", newvalue);      } } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -