My goal is to create a delphi XE8 project (VCL or fireMonkey) that will interact with webbrowser.
I want to use the power of JS (jquery) to access DOM, extract some data and send them back to delphi.
I try to use twebbrowser and... any page gives me tons of JS errors : I think twebbroser is based on a very old browser such as Internet explorer8
I run windows7 + IE11
1) Should I go to chromium browser ? (Tchromoium or chromiumembedded ?)
2) How to make it communicate with Jquery ?
Regards
Related
I am familiar with programming in Delphi stand-alone applications and web-server applications.
Is it possible to have a Delphi application that when launched gets the browser to handle its output? Without a server being between the user and the application.
The reason I would like to do this is because HTML CSS and so on provide a more familiar user-interface to most people.
You can not "let the browser handle its output" without any HTTP connection, so a local web server, then using regular URIs like http://localhost:888/myDelphiApp/FullURI.
What you can is to embed a Web Browser to your Delphi application, then provide the generated web content not via HTTP, but as local content.
You may use
THtmlViewer Open Source component - which I like very much;
Delphi Chromium Embedded;
WebBrowser Component.
All recognize CSS and HTML content.
There are known ways of writing ActiveX plugins with Delphi, but the ActiveX itself poses a lot of limitations in browsers other than IE. So I was thinking - how to compile a plugin in NPAPI format, natively compatible with Chrome/Firefox?
Intent of the plugin is to allow to embed a VCL form into the HTML page and be able to bi-directionaly communicate with this form using JavaScript. E.g. clicking a button on a form would call JavaScript function on the page, and JavaScript functions on the page could send events to a VCL form. How this can be achieved?
There's a list of existing NPAPI wrappers for Delphi at Mozilla bugtracker: https://www.mozdev.org/bugs/show_bug.cgi?id=8708
The latest entry (NPAPI plugin framework with scripting support + demo by Yury Sidorov) offers exactly what is needed.
With that VCL Form project can be compiled into a DLL compatible with NPAPI. Manifest.json also needs to be added. Afterwards the plugin can be installed into Chrome like usual.
Following HTML code embeds the VCL form that is stored in the plugin:
<EMBED id="embed1" TYPE="application/x-delphi-demo-plugin" ALIGN=CENTER WIDTH=400 HEIGHT=300>
<script>
var embed1 = document.getElementById('embed1');
</script>
<input type=button value="Show Value" onclick='alert("Value=" + embed1.value);'>
And that is how Form can change the HTML page around it:
with Plugin.GetBrowserWindowObject do
GetObject('document')['bgColor'] := clRed;
P.S. The only fix that should be applied for modern Delphi versions - change string and PChar to AnsiString and PAnsiChar throughout the NPPlugin.pas. Or else communication with embedded form is broken.
I'm using Delphi XE2 in Windows 7 64 bit, I put TWebBrowser component in a Form. I navigate it to a blogspot website, e.g:
Webbrowser1.Navigate('http://maniacpcgame.blogspot.com');
it shows JavaScript Error (HTML Parsing Error), then I turn Silent properties to True as follow:
Webbrowser1.Silent := true;
Webbrowser1.Navigate('http://maniacpcgame.blogspot.com');
But the browser cannot open the page properly (only show background image). I tried other blogspot websites and got same problem. Any solution to display blogspot website correctly in TWebBrowser?
Twebbrowser uses IEFRAME
IEFRAME depends on the version of internet explorer you are running on that computer
You can deploy IEFRAME.DLL (in c:windows/system32 )with your application so you can be sure the same version is used everywhere so you wont get inconsistencies between computers.
However newer ones wont work on XP and there are some directx requirements.
A good alternative is
Delphi Embed chromium, it makes your deployed application a lot bigger (+-15MB) but you can be very sure it works everywhere and always (windows 8 to XP) and it will always produce the same page
Also if you have to manipulate the DOM or insert javascript (to communicate with the page)
this will be easier and will work more consistently.
Here is a link for the latest version:
https://code.google.com/p/dcef3/
I've been testing some samples to save webpages using TDownloadUrl, and it was really amazing, but I found some problems certain webpages, those pages cannot let to access to real content because they need to start a session o set a cookie before, so I get two situations, TDownloadUrl does...
not create/save a file with content from webpage supposedly downloaded (STATUS CODE : 5 --> dsEndDownloadData), this is because there is no cookie (STATUS CODE : 41 --> dsCookieStateDowngrade)
not save the content right instead of it saves a webpage requesting to press a link to access to content wished
Is there any way to bypass these problems using Delphi's native components, that is, no third-party components (like TEmbeddedWB)?
Thanks in advance.
Note: I'm using Delphi XE2 under WinXP with Firefox 6.0 and IE 9.0
XE2 ships with Indy 10 (which is a third-party component, but at least it is a bundled one). You can use its TIdHTTP component instead of TDownloadURL. TIdHTTP supports cookies.
We are trying to change the builtin browser component from TWebBrowser to TChromium.
It is used mostly for displaying maps from Google and Bing. The communication from the javascript to Delphi is done with COM.
When trying to change the browser to TChromium it fails to compile this code.
if supports(fBrowser.defaultInterface, IOleObject, fOLE) then
because defaultInterface is missing from TChromium.
EDIT:
Is it possible to still communicate from javascript to Delphi with Chromium?
I'm aware of that they are not compatible and I have to rewrite code. I just want to know how to get a result from javascript to delphi. Note I am using Delphi 2007 so the extended RTTI cannot be used.
Regards
Roland Bengtsson
I never used it myself, but TChromium appears to be a wrapper around the "Chromium" web browser, while the original TWebBrowser from Delphi is a wrapper around an IE Browser.
TWebBrowser.defaultInstance gives you the COM object of the IE Browser. For the Chromium browser you can apparently use TChromium.Browser, it gives you an object of type ICefBrowser. The TChromium people were smart not to name the property defaultInstance because there's a lot of code out there casting from the return of defaultInstance to other interface types: If TChromium.Browser was named the same, the cast would compile and fail at run time. Because the IE Browser is obviously not a Chrome browser, and I doubt the Chromium browser fully implements all IE interfaces.
Using TChromium, you can invoke scripts easily via ExecuteJavaScript. And you can invoke Delphi code from scripts, which you can use to send return values back from a JavaScript function to Delphi.
See this question and my answer there about doing this using extensions.
There also seems to be work in progress for functions like EexecuteScriptAndReturnValue but as the time of writing they are not contained in the trunk.
And regarding TWebBrowser.DefaultInterface I agree with Cosmin: the best analogy is probably TChromium.Browser as you can access frames and subsequently DOM, etc. from there.