Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
Return function JavaScrit in Delphi
-
- Posts: 7
- Joined: Sun Jan 28, 2018 12:38 pm
Return function JavaScrit in Delphi
Hello,
What would be the best using CEF4 to capture the return of a javascript function executed on Chromium:
For example:
function sum (a, b) {
return a + b
}
what better way to get that return in Delphi?
What would be the best using CEF4 to capture the return of a javascript function executed on Chromium:
For example:
function sum (a, b) {
return a + b
}
what better way to get that return in Delphi?
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Return function JavaScrit in Delphi
Hi,
Register a JavaScript extension to call custom functions that execute Delphi code. That code can send a process message to send any information to the browser process.
The JSExtension demo shows how to do all that. Read the code comments for all the details.
Register a JavaScript extension to call custom functions that execute Delphi code. That code can send a process message to send any information to the browser process.
The JSExtension demo shows how to do all that. Read the code comments for all the details.
Re: Return function JavaScrit in Delphi
you can use Chromium1ConsoleMessage
To output a message to the console on JS:
Form1.Chromium1.Browser.MainFrame.ExecuteJavaScript('var body =(myText);console.log("text="+body);', 'about:blank', 0);
To output a message to the console on JS:
Form1.Chromium1.Browser.MainFrame.ExecuteJavaScript('var body =(myText);console.log("text="+body);', 'about:blank', 0);
-
- Posts: 7
- Joined: Sun Jan 28, 2018 12:38 pm
Re: Return function JavaScrit in Delphi
Yes, but I would not like to use the console, because it is running all the time in the application, I wanted something only when it was really the return of a js functionzavet wrote: Sat Apr 11, 2020 1:13 am you can use Chromium1ConsoleMessage
To output a message to the console on JS:
Form1.Chromium1.Browser.MainFrame.ExecuteJavaScript('var body =(myText);console.log("text="+body);', 'about:blank', 0);
-
- Posts: 8
- Joined: Wed Mar 18, 2020 4:18 am
Re: Return function JavaScrit in Delphi
You can simply call JS: Alert( needed_result )
And intercept (and supress) this result in Jsdialog event
And intercept (and supress) this result in Jsdialog event

- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Return function JavaScrit in Delphi
Nice trick!ForumReader wrote: Sun Apr 12, 2020 12:06 pm You can simply call JS: Alert( needed_result )
And intercept (and supress) this result in Jsdialog event![]()

Re: Return function JavaScrit in Delphi
what's the text size limit ?? if you knowsalvadordf wrote: Sun Apr 12, 2020 12:59 pmNice trick!ForumReader wrote: Sun Apr 12, 2020 12:06 pm You can simply call JS: Alert( needed_result )
And intercept (and supress) this result in Jsdialog event![]()
![]()

- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Return function JavaScrit in Delphi
CEF4Delphi has the same limits as the Delphi strings (up to 2GB if you use unicode strings) but I don't know if CEF or Chromium has some other limit.shobits1 wrote: Mon Apr 13, 2020 4:43 pmwhat's the text size limit ?? if you knowsalvadordf wrote: Sun Apr 12, 2020 12:59 pmNice trick!ForumReader wrote: Sun Apr 12, 2020 12:06 pm You can simply call JS: Alert( needed_result )
And intercept (and supress) this result in Jsdialog event![]()
![]()
![]()
Re: Return function JavaScrit in Delphi
OK, thanks
I'll test it when I have time, it may make my code simpler instead of using callbacks from jsExtension, although I don't know how much it'll affect the CEF performance.
I'll test it when I have time, it may make my code simpler instead of using callbacks from jsExtension, although I don't know how much it'll affect the CEF performance.
Re: Return function JavaScrit in Delphi
Limits for JS alert text is 10240byte
Limit for JS prompt
so alert has a limit to about 10KByte, prompt has the same limit on message(messageText), but no limit on value (defaultPromptText) tested up to 200,000,000 in length.
Code: Select all
let s = ''
for( i = 0; i < 1000*1000; i++){
s += '.';
}
// in browser console
// s.length = 1,000,000
alert(s);
// delphi received messageText length = 10,240
Limit for JS prompt
Code: Select all
let s = '';
let s100 = '';
for( i = 0; i < 100; i++){
s100 += '.';
}
for( i = 0; i < 1000*1000; i++){
s += s100;
}
// in browser console
// s.length = 100,000,000
prompt(s, s);
// delphi received messageText length = 10,240
// defaultPromptText length = 100,000,000