Compartir a través de


IDeveloperConsoleMessageReceiver interface

The IDeveloperConsoleMessageReceiver interface is implemented by client applications that wish to receive console log messages from Windows Internet Explorer.

Members

The IDeveloperConsoleMessageReceiver interface inherits from the IUnknown interface. IDeveloperConsoleMessageReceiver also has these types of members:

  • Methods

Methods

The IDeveloperConsoleMessageReceiver interface has these methods.

Method Description
Write

Used to log a message from Internet Explorer.

WriteWithUrl

Used to log a message from Internet Explorer that also contains the URL that originated the issue.

WriteWithUrlAndLine

Used to log a message from Internet Explorer that also contains the URL and line number.

WriteWithUrlLineAndColumn

Used to log a message from Internet Explorer that also contains the URL, line number, and column offset.

 

Remarks

In Internet Explorer 10, applications such as developer tools can register to receive messages logged by Internet Explorer that provide diagnostic information intended for developers. A full list of the messages can be found in F12 developer tools console error messages.

To subscribe for console messages, an application registers with Internet Explorer by executing the IDM_ADDCONSOLEMESSAGERECEIVER command via an IOleCommandTarget interface on the document. In the IOleCommandTarget, a VARIANT containing the IUnknown pointer to the implementation of the subscriber (IDeveloperConsoleMessageReceiver) and an out parameter, which will be filled by Internet Explorer as the unique cookie to for the listener. The subscriber is invoked every time a message is logged in Internet Explorer. To unsubscribe, the application passes in another command IDM_REMOVECONSOLEMESSAGERECEIVER with the cookie it received when registering.

Multiple subscribers can be registered at a time.

Examples

An application subscribes by executing a command via IOleCommandTarget on the document with the MSHTML command group and command ID for subscribing to console messages. The subscriber also passes in a pointer to its IUnknown implementation, which is queried for the listener interface. Subscribers are issued a cookie (an unique identifier) which they must persist and use later when unsubscribing.

The example below assumes a reference to IWebBrowser2 has already been obtained.

CComPtr<IDispatch> spDocDisp;
hr = IWebBrowser2->get_Document(&spDocDisp);
if (hr == S_OK)
{
    CComQIPtr<IOleCommandTarget> spOleCommandTarget(spDocDisp);
    If (spOleCommandTarget != nullptr)
    {
        spOleCommandTarget->Exec(  &CGID_MSHTML,
                          IDM_ADDCONSOLEMESSAGERECEIVER,
                          OLECMDEXECOPT_DODEFAULT,
                          &varListener,
                          &varConsoleCookie);

     }
}

To unsubscribe, the application calls IOleCommandTarget::Exec method again with the cookie that was received when subscribing.

pOleCommandTarget->Exec(  CGID_MSHTML,
                          IDM_REMOVECONSOLEMESSAGERECEIVER,
                          OLECMDEXECOPT_DODEFAULT,
                          &varConsoleCookie,
                          NULL);

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Header

Mshtml.h

IDL

Mshtml.idl