chromium - How can I get IHtmlDocument2 in chrome browser? -
in internet explorer, can use ihtmldocument2 html document.
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 begin document := currentie.document; document.queryinterface(iid_ihtmldocument2, rootnode); innerhtml := rootnode.body.innerhtml; end; 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 <> nil 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 (pdoc.parentwindow iserviceprovider).queryservice(iwebbrowserapp, iwebbrowser2, ie); freelibrary(hinst); end; end;
i used spy++ chrome frame handle, , found them.
wnd := getforegroundwindow; wndchild := findwindowex(wnd, 0, 'chrome_widgetwin_0', nil); wndchild := findwindowex(wndchild, 0, 'chrome_renderwidgethosthwnd', nil); wndchild := findwindowex(wndchild, 0, 'compositorhostwindowclass', nil);
but can't catch result in function called objectfromlresult.
objectfromlresult(lres, ihtmldocument2, 0, pdoc);
the error code got 127.
does mean chrome browser not support way fetch html document?
if answer yes, there way catch it?
thanks lot.
ps: have tried use msaa tree, didn't work too.(can fetch title)
this not possible, ihtmldocument2 interface supported in ie hosting objects, webkit engine used in chrome doesn't support it. can use msaa access elements, need enable accessibility feature first: http://www.chromium.org/developers/design-documents/accessibility
or alternatively can access dom via remote debugging protocol: https://developers.google.com/chrome-developer-tools/docs/protocol/1.0/index
Comments
Post a Comment