Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get IHtmlDocument2 in chrome browser?
    primarykey
    data
    text
    <p>In Internet Explorer, I can use IHtmlDocument2 to get the html document.</p> <pre><code>function GetCurrentBrowserDOM: WideString; var hr: HRESULT; CurrentIE: IWebbrowser2; Wnd: HWND; WndChild:HWND; document: IDispatch; RootNode: IHTMLDocument2; innerHtml: WideString; begin Result := ''; Wnd := GetForegroundWindow; WndChild := FindWindowEx(Wnd, 0,'Frame Tab', nil); WndChild := FindWindowEx(WndChild, 0,'TabWindowClass', nil); WndChild := FindWindowEX(WndChild, 0, 'Shell DocObject View', nil); WndChild := FindWindowEX(WndChild, 0, 'Internet Explorer_Server', nil);//find Internet CoInitialize(nil); try hr := GetIEFromHWND(WndChild, CurrentIE); if hr = S_OK then begin document := CurrentIE.Document; document.QueryInterface(IID_IHTMLDocument2, RootNode); innerHtml := RootNode.body.innerHTML; end; finally CoUninitialize; end; end; function GetIEFromHWND(WHandle: HWND; var IE: IWebbrowser2): HRESULT; type TObjectFromLResult = function(LRESULT: LRESULT; const IID: TGUID; wParam: WPARAM; out PObject): HRESULT; stdcall; var hInst: HWND; lRes: Cardinal; MSG: Integer; pDoc: IHTMLDocument2; ObjectFromLresult: TObjectFromLresult; begin hInst := LoadLibrary('Oleacc.dll'); @ObjectFromLresult := GetProcAddress(hInst, 'ObjectFromLresult'); if @ObjectFromLresult &lt;&gt; nil then begin try MSG := RegisterWindowMessage('WM_HTML_GETOBJECT'); SendMessageTimeOut(WHandle, MSG, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes); Result := ObjectFromLresult(lRes, IHTMLDocument2, 0, pDoc); Result := GetLastError; if Result = S_OK then (pDoc.parentWindow as IServiceprovider).QueryService(IWebbrowserApp, IWebbrowser2, IE); finally FreeLibrary(hInst); end; end; </code></pre> <p>I used spy++ to look for the chrome frame handle, and I found them.</p> <pre><code> Wnd := GetForegroundWindow; WndChild := FindWindowEx(Wnd, 0, 'Chrome_WidgetWin_0', nil); WndChild := FindWindowEx(WndChild, 0, 'Chrome_RenderWidgetHostHWND', nil); WndChild := FindWindowEx(WndChild, 0, 'CompositorHostWindowClass', nil); </code></pre> <p>But it can't catch the result in function called ObjectFromLresult.</p> <pre><code>ObjectFromLresult(lRes, IHTMLDocument2, 0, pDoc); </code></pre> <p>The error code I got was 127.</p> <p>Does it mean chrome browser not support this way to fetch its html document?</p> <p>If the answer is yes, is there another way to catch it?</p> <p>thanks a lot.</p> <p>PS: I have tried to use MSAA tree, but it didn't work too.(Can only fetch the title)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload