- WebBrowser (MSIE) - Capture JS Errors using Exec of IOleCommandTarget
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>TEST SCRIPT</title>
- </head><body>
- <script type="text/javascript">
- document.body.style.background='yellow';
- setTimeout(function(){
- document.body.style.background='red';
- causeERROR(); // purposefully undefined function
- document.body.style.background='green';
- },500);
- </script>
- </body>
- </html>
- type
- TNulWBContainer = class(TWebBrowser, IUnknown, IOleClientSite,
- IDocHostUIHandler, IDispatch, IOleCommandTarget)
- protected
- { OTHER STUFF }
- {IOleCommandTarget Interface}
- function QueryStatus(CmdGroup: PGUID; cCmds: Cardinal;
- prgCmds: POleCmd; CmdText: POleCmdText): HResult; stdcall;
- function Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
- const vaIn: OleVariant; var vaOut: OleVariant): HResult; stdcall;
- end;
- implementation
- { OTHER STUFF }
- function TNulWBContainer.QueryStatus(CmdGroup: PGUID; cCmds: Cardinal;
- prgCmds: POleCmd; CmdText: POleCmdText): HResult; stdcall;
- begin
- prgCmds.cmdf := OLECMDF_ENABLED;
- Result := S_OK; //inherited QueryStatus(CmdGroup,cCmds,prgCmds,CmdText);
- end;
- function TNulWBContainer.Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD;
- const vaIn: OleVariant; var vaOut: OleVariant): HResult; stdcall;
- begin
- ShowMessage('nCmdID=$'+IntToHex(nCmdID,8));
- Result:=OLECMDERR_E_UNKNOWNGROUP;
- end;
- end.
- uses Registry;
- // ...
- with TRegistry.Create do
- try
- RootKey:=HKEY_CURRENT_USER;
- if OpenKey('SoftwareMicrosoftInternet ExplorerMain',False) then begin
- WriteString('DisableScriptDebuggerIE','no');
- WriteString('Disable Script Debugger','yes');
- CloseKey;
- end;
- finally
- Free;
- end;
- // ...