Dave Nottage 580 Posted October 5, 2024 3 hours ago, Dave Nottage said: It appears Android's WebView does not like part of the JavaScript (it works on macOS and iOS). I'm looking into it I discovered what the problem is: The "default" TWebBrowser implementation for Android uses loadUrl: procedure TAndroidWebBrowserService.EvaluateJavaScript(const AJavaScript: string); begin FWebView.loadUrl(StringToJString('javascript:' + AJavaScript)); UpdateContentFromControl; end; Which I guess does not accept the JavaScript that I provided. In TWebBrowserExt, it uses the evaluateJavascript method: procedure TPlatformWebBrowserExt.ExecuteJavaScript(const AJavaScript: string; const AHandler: TJavaScriptResultProc); begin if FWebView <> nil then FWebView.evaluateJavascript(StringToJString(AJavaScript), CreateValueCallback(AHandler)) else AHandler(cJavaScriptNullResult, -1); end; Which does work. I've now added a demo to the HowTo repository, which uses TWebBrowserExt, and it works on Android (as well as iOS and macOS) Share this post Link to post
MMSoft 0 Posted October 5, 2024 Sorry I can't get it to work, I already have a long list of folders in which Delphi contains the necessary files, and I have the idea that now all files can be found. But now I get this error message: [DCC Error] Unit1.pas(69): E2003 Undeclared identifier: 'cJavaScriptClickAtXY' It's possible that I'm using the wrong (outdated) file Share this post Link to post
Dave Nottage 580 Posted October 5, 2024 1 hour ago, MMSoft said: I have the idea that now all files can be found. But now I get this error message: [DCC Error] Unit1.pas(69): E2003 Undeclared identifier: 'cJavaScriptClickAtXY' The demo shows all the required folders in the Search path of Project Options. For that identifier you'd be missing the Features\JavaScript folder of Kastri Share this post Link to post
MMSoft 0 Posted October 6, 2024 Just downloaded the latest version: https://github.com/DelphiWorlds/Kastri And set up these search paths: C:\Users\mvsan\Downloads\Kastri-master\Kastri-master\Core C:\Users\mvsan\Downloads\Kastri-master\Kastri-master\API C:\Users\mvsan\Downloads\Kastri-master\Kastri-master\Controls C:\Users\mvsan\Downloads\Kastri-master\Kastri-master\Features\JavaScript C:\Users\mvsan\Downloads\Kastri-master\Kastri-master\Features\WebBrowserExt But keep getting this error message: [DCC Error] Unit1.pas(69): E2003 Undeclared identifier: 'cJavaScriptClickAtXY' [DCC Error] Unit1.pas(69): E2250 There is no overloaded version of 'Format' that can be called with these arguments Share this post Link to post
Dave Nottage 580 Posted October 7, 2024 (edited) 13 hours ago, MMSoft said: [DCC Error] Unit1.pas(69): E2003 Undeclared identifier: 'cJavaScriptClickAtXY' It's definitely in the repo. https://github.com/DelphiWorlds/Kastri/blob/58569bee28f5ce3caf5ceef588a46d13c161ce62/Features/JavaScript/DW.JavaScript.pas#L20 Did you add DW.JavaScript to the uses clause, as per the demo? Edited October 7, 2024 by Dave Nottage Share this post Link to post
MMSoft 0 Posted October 7, 2024 (edited) Of course, I use the demo, but my files are in a different place, so your search paths don't work for me. I'm getting this message now: Could not find a part of the path 'C:\Users\mvsan\Documents\Embarcadero\Studio\Projects\TEST\Lib\dw-kastri-base-3.0.0.jar'. Edited October 7, 2024 by MMSoft Share this post Link to post
Dave Nottage 580 Posted October 7, 2024 2 minutes ago, MMSoft said: Could not find a part of the path 'C:\Users\mvsan\Documents\Embarcadero\Studio\Projects\TEST\Lib\dw-kastri-base-3.0.0.jar'. The jar is not added to the search paths, it's added to the Libraries node of the Android 32-bit target, as per the demo readme. This is an image (which has been shortened, for brevity) of it: 4 minutes ago, MMSoft said: I've added these Search Paths for this: You don't add those paths. See above. Share this post Link to post
MMSoft 0 Posted October 7, 2024 (edited) Thanks, it works. I'm now going to try to incorporate it into my own Project. Edit: Is it possible to make a keyboard appear when the magnifying glass is clicked (Search on the site) so that search text can be typed ? Edit2: It now also works in my own App (and it runs on an Android TV). I do come across points for improvement, such as showing a keyboard when there is an input field. But also if the site does not fit on the Web browser to be able to scroll it. Also, if the site has shifted on the WebBrowser, clicking on it will no longer work because this shift will probably have to be taken into account. Edited October 7, 2024 by MMSoft Share this post Link to post
MMSoft 0 Posted October 10, 2024 (edited) I've been trying for days to get a little further, but unfortunately I can't get any further. For example, I try to ask how many pixels a site is shifted on the WebBrowser. How could I do that? Edit: Because I can't find how to do this, I'm trying to get it done through AI. It comes with the code below, but there I get the error messages: E2034 Too many actual parameters By the rules: procedure(const AResult: string) const JavaScriptHorizontal = 'window.scrollX'; JavaScriptVertical = 'window.scrollY'; procedure TForm1.WebBrowser1DidFinishLoad(ASender: TObject); begin // JavaScript om de huidige horizontale schuifpositie op te halen WebBrowser1.EvaluateJavaScript(JavaScriptHorizontal, procedure(const AResult: string) begin ShowMessage('Horizontaal verschoven: ' + AResult); end ); // JavaScript om de huidige verticale schuifpositie op te halen WebBrowser1.EvaluateJavaScript(JavaScriptVertical, procedure(const AResult: string) begin ShowMessage('Verticaal verschoven: ' + AResult); end ); end; Edited October 11, 2024 by MMSoft Share this post Link to post
MMSoft 0 Posted October 16, 2024 (edited) I now have a cursor and when I click on a button it executes it (if the page is not moved on the TWebBrowser). Thank you for that! Now my goal is to be able to view a website and use it on an android TV. I had hoped that if I could display a cursor and click on an item I could use a website, but that turns out to be a lot more difficult for me. The 1st problem I run into is that sometimes a site is too big, and it needs to be able to scroll. I have no idea how to make that happen. The 2nd problem is if the site is shifted on the TWebBrowser, clicking on a button on the site no longer works. And the 3rd problem I run into is, how can I enter something on an input field on the site ? Unfortunately, I can't figure this out, and help is very welcome Edited October 16, 2024 by MMSoft Share this post Link to post
MMSoft 0 Posted Monday at 03:08 PM Unfortunately I haven't gotten any further with this, and I wonder if this is possible with FMX. If it is possible, who can help me with this? Share this post Link to post
PeaShooter_OMO 18 Posted Tuesday at 06:34 AM @MMSoft I don't know if you are aware but your approach should foremostly be from a Web Development perspective. Any question you have about how to achieve anything related to your project should be evaluated to see if it is related to web developement or not. For instance; You wanted to know what the position of the page is relative to the scrolled area. That is a web development question and as such you should ask the question on Google for Javascript. In the Firebird browser there is an add-on called Greasemonkey. It allows you to write Javascript scripts that you can run on any website you choose. I do not know what you can use for Chrome, etc. So what you would do is you will ask yourself what you need to do, one step at a time, in this case find out the scroll offset of the currently loaded page. You will search on Google for a solution for that in Javascript. You will create a Greasemonkey script to do only that single step and then test it on your website via Firebird and Greasemonkey. This way you can quickly iterate possible solutions without having to try and build it into Delphi. Once you found the solutions to all your required steps then you build it into Delphi, worrying only about the aspect of getting your Javascript into the TWebBrowser or alternative and fixing whatever limitations the TWebBrowser might present. This obviosuly will require you to learn other developement tools but it is worth it. Share this post Link to post
PeaShooter_OMO 18 Posted Thursday at 11:03 AM On 2/18/2025 at 8:34 AM, PeaShooter_OMO said: Firebird browser I aplogize; I meant Firefox browser Share this post Link to post