Page 2 of 2
Re: Get document
Posted: Tue Aug 20, 2019 12:13 pm
by X11
error at line "SimpleNodeSearch(TempVisitor, 'link-ajax j-v-contacts-expand-link');"
[dcc32 Error] uMiniBrowser.pas(1045): E2010 Incompatible types: 'ICefDomDocument' and 'TCefFastDomVisitor2'
Code: Select all
procedure TMiniBrowserFrm.Chromium1ProcessMessageReceived(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
sourceProcess: TCefProcessId; const message: ICefProcessMessage;
out Result: Boolean);
Var
TempFrame : ICefFrame;
TempVisitor : TCefFastDomVisitor2;
begin
Memo1.Lines.Add('TMiniBrowserFrm.Chromium1ProcessMessageReceived');
Result := False;
if (message = nil) or (message.ArgumentList = nil) then exit;
if message.Name = MSG1 then
begin
Memo1.Lines.Add(message.ArgumentList.GetString(0));
Memo1.Lines.Add(MSG1);
TempFrame := browser.MainFrame;
if (TempFrame <> nil) then
begin
TempVisitor := TCefFastDomVisitor2.Create(browser, TempFrame, DOMVisitor_OnDocAvailable);
TempFrame.VisitDom(TempVisitor);
// error here
SimpleNodeSearch(TempVisitor, 'link-ajax j-v-contacts-expand-link');
end;
end;
Result := True;
end;
Re: Get document
Posted: Wed Aug 21, 2019 5:40 am
by X11
up
Re: Get document
Posted: Wed Aug 21, 2019 7:32 am
by salvadordf
That procedure needs a ICefDomDocument parameter and it's usually called inside the TCefFastDomVisitor2 function.
I would suggest you to use the DOMVisitor demo as a template for your application.
Re: Get document
Posted: Wed Aug 21, 2019 9:11 am
by X11
Yes? I am using "DOMVisitor" and "procedure SimpleNodeSearch(const aDocument: ICefDomDocument)" where is ICefDomDocument.
Code: Select all
procedure TMiniBrowserFrm.Chromium1ProcessMessageReceived(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
sourceProcess: TCefProcessId; const message: ICefProcessMessage;
out Result: Boolean);
Var
TempFrame : ICefFrame;
TempVisitor : TCefFastDomVisitor2;
begin
Memo1.Lines.Add('Chromium1ProcessMessageReceived-1');
Result := False;
if (message = nil) or (message.ArgumentList = nil) then exit;
if message.Name = MSG1 then
begin
Memo1.Lines.Add(message.ArgumentList.GetString(0));
Memo1.Lines.Add(MSG1);
TempFrame := browser.MainFrame;
if (TempFrame <> nil) then
begin
Memo1.Lines.Add('Chromium1ProcessMessageReceived-2');
TempVisitor := TCefFastDomVisitor2.Create(browser, TempFrame, DOMVisitor_OnDocAvailableSearch);
TempFrame.VisitDom(TempVisitor);
end;
end;
Result := True;
end;
procedure DOMVisitor_OnDocAvailableSearch(const browser: ICefBrowser; const frame: ICefFrame; const document: ICefDomDocument);
var
msg: ICefProcessMessage;
begin
MiniBrowserFrm.Memo1.Lines.Add('DOMVisitor_OnDocAvailableSearch');
// Simple DOM iteration example
SimpleDOMIteration(document);
// Simple DOM searches
SimpleNodeSearch(document);
end;
in memo I see "Chromium1ProcessMessageReceived-1" and "Chromium1ProcessMessageReceived-2", but no "DOMVisitor_OnDocAvailableSearch"
Re: Get document
Posted: Fri Aug 23, 2019 5:41 am
by X11
up
Re: Get document
Posted: Fri Aug 23, 2019 7:08 am
by salvadordf
Sorry for the delay.
DOMVisitor_OnDocAvailableSearch is executed when CEF calls TCefFastDomVisitor2.Visit, which happens in the render process :
https://magpcss.org/ceforum/apidocs3/pr ... sitor.html
MiniBrowserFrm.Memo1 can only be accessed from the browser process.
You need to use a process message to send information from the DOMVisitor_OnDocAvailableSearch procedure in the render process to the browser process like this :
https://github.com/salvadordf/CEF4Delph ... r.pas#L250
Re: Get document
Posted: Sat Aug 24, 2019 2:59 pm
by X11
Sorry.
I already got confused completely
Ok, I want to get some source text from the page into Memo1.
I have to start search process.
1. In Chromium1LoadEnd I execute "DOMVisitor_OnDocAvailableSearch":
Code: Select all
procedure TMiniBrowserFrm.Chromium1LoadEnd(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
httpStatusCode: Integer);
VAR
TempVisitor : TCefFastDomVisitor2;
begin
if Assigned(frame) then
begin
Memo1.Lines.Add('frame load end, name: ' + frame.Name);
Memo1.Lines.Add('frame load end, url: ' + frame.Url);
end;
if frame.IsMain then
begin
Memo1.Lines.Add('main frame load end: ' + TimeToStr(now));
Chromium1.Browser.MainFrame.ExecuteJavaScript(MemoJS.Text, Chromium1.Browser.MainFrame.Url, 0);
TempVisitor := TCefFastDomVisitor2.Create(browser, Frame, DOMVisitor_OnDocAvailableSearch);
frame.VisitDom(TempVisitor);
end;
end;
2. ??
Re: Get document
Posted: Sat Aug 24, 2019 3:43 pm
by X11
2. In DOMVisitor_OnDocAvailableSearch I can GetElementById. And then send message to Chromium1
Code: Select all
procedure DOMVisitor_OnDocAvailableSearch(const browser: ICefBrowser; const frame: ICefFrame; const document: ICefDomDocument);
var
msg: ICefProcessMessage;
n: iCefDomNode;
begin
n := document.GetElementById('ad-author-contact-row-label');
msg := TCefProcessMessageRef.New(MSG1);
msg.ArgumentList.SetString(0, 'MSG1, document.Title : ' + document.Title);
if n <> nil then
msg.ArgumentList.SetString(1, 'MSG1, document. : ' + n.AsMarkup)
else
msg.ArgumentList.SetString(1, 'MSG1, Element "ad-author-contact-row-label" not found');
frame.SendProcessMessage(PID_BROWSER, msg);
end;
is this code correct?
Re: Get document
Posted: Mon Aug 26, 2019 8:14 am
by salvadordf
You need to create TCefFastDomVisitor2 and call frame.VisitDOM in the render process.
Read this post for more information :
https://www.briskbard.com/forum/viewtop ... 4023#p4023