Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 25th, 2012  |  syntax: None  |  size: 2.06 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. WebBrowser (MSIE) - Capture JS Errors using Exec of IOleCommandTarget
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.     <head>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.         <title>TEST SCRIPT</title>
  7.     </head><body>
  8.         <script type="text/javascript">
  9.             document.body.style.background='yellow';
  10.             setTimeout(function(){
  11.                 document.body.style.background='red';
  12.                 causeERROR(); // purposefully undefined function
  13.                 document.body.style.background='green';
  14.             },500);
  15.         </script>
  16.     </body>
  17. </html>
  18.        
  19. type
  20.   TNulWBContainer = class(TWebBrowser, IUnknown, IOleClientSite,
  21.                           IDocHostUIHandler, IDispatch, IOleCommandTarget)
  22.   protected
  23.     { OTHER STUFF }
  24.     {IOleCommandTarget Interface}
  25.     function QueryStatus(CmdGroup: PGUID; cCmds: Cardinal;
  26.       prgCmds: POleCmd; CmdText: POleCmdText): HResult; stdcall;
  27.     function Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
  28.       const vaIn: OleVariant; var vaOut: OleVariant): HResult; stdcall;
  29.     end;
  30.  
  31. implementation
  32.  
  33. { OTHER STUFF }
  34.  
  35. function TNulWBContainer.QueryStatus(CmdGroup: PGUID; cCmds: Cardinal;
  36.   prgCmds: POleCmd; CmdText: POleCmdText): HResult; stdcall;
  37. begin
  38.   prgCmds.cmdf := OLECMDF_ENABLED;
  39.   Result := S_OK; //inherited QueryStatus(CmdGroup,cCmds,prgCmds,CmdText);
  40. end;
  41.  
  42. function TNulWBContainer.Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
  43.   const vaIn: OleVariant; var vaOut: OleVariant): HResult; stdcall;
  44. begin
  45.   ShowMessage('nCmdID=$'+IntToHex(nCmdID,8));
  46.   Result:=OLECMDERR_E_UNKNOWNGROUP;
  47. end;
  48.  
  49. end.
  50.        
  51. uses Registry;
  52.  
  53. // ...
  54.  
  55.   with TRegistry.Create do
  56.     try
  57.       RootKey:=HKEY_CURRENT_USER;
  58.       if OpenKey('SoftwareMicrosoftInternet ExplorerMain',False) then begin
  59.         WriteString('DisableScriptDebuggerIE','no');
  60.         WriteString('Disable Script Debugger','yes');
  61.         CloseKey;
  62.       end;
  63.     finally
  64.       Free;
  65.     end;
  66.  
  67. // ...