Comments (5)
Hi,
Its up to you to serialize the params passed in EvaluateScriptFunction
. There's a EvaluateScriptFunctionWithSerializedParams
but its protected. If you want to use it you may create an inherited Webview
class.
As for passing large amounts of data from c# to js, I recommend following another approach, which is call a JS method that then requests the information to c#. That's probably more efficient when you have large amounts of data, check this test:
from webview.
Ok got it !
I wrote this based on the unit test you gave me, on my own code and javascript is receiving the data.
var testObject = new TestObject()
{
Age = 33,
Kind = Kind.B,
Name = "John",
Parent = new TestObject()
{
Name = "John Parent",
Age = 66,
Kind = Kind.C
}
};
Func functionToCall = () => { return testObject; };
webviewChart.RegisterJavascriptObject("functionToCall", functionToCall);
var scriptAux = $"functionToCall.invoke().then(result=>console.log(result));";
var xresult = await webviewChart.EvaluateScript(scriptAux);
Thanks !
from webview.
Just to wrap up, I was doing some performance tests on the above code I posted, and I was having relatively bad performance for what we wanted.
So re-read again your comment, and had a different perspective the second time around.
I am now calling a pre-registered function in javascript from C# called executeFunctionInQueue.
This function in js will then call a function in C# which would request the next function to be executed in the queue (which is simply json data with the name of the function and a lot of test random data)
Javascript would receive the data , deserialize and execute the respective function with the embedded data.
Performance wise, the last post I was having around 30 to 40 ms, no less than that per execution.
I am now getting 1 to 3 ms average.
It is quite the convoluted way of calling functions and passing data around, but at least got a good performance
from webview.
Since there's no issue on the WebView side I'll close this
from webview.
I think I've found a workaround for this.
The EvaluateScriptFunction still doesn't work for me if I want to pass non integer data
However, using the function EvaluateScript I managed to create a script where I do the actual call of the function.
I ran this from C#:
(Note: see the sendDataToGuest('testdata'); fuction call)
string script = @"
console.log(before
);
var result = hostToGuestSystemInterface.sendDataToGuest('testdata');
console.log(after
);
return result`;
".Replace(Environment.NewLine, "");
var result = await webviewChart.EvaluateScript(script);
This works... the plan is to pass in json serialized object to that function to pass relatively large amounts of data.
Either way, would be good to know if this is the optimal way to pass data to js.
Thanks in advance
from webview.
Related Issues (20)
- microphone permission denied HOT 2
- Change cursor type over links HOT 10
- Nuget.config "Avalonia" feed needs to be changed HOT 1
- Error: libcef missing with CefGlue.Avalonia 117.5938.2 on Win/Avalonia 11
- Passing chromium flags HOT 3
- Libraries missing when running 2.117.1-avalonia11 on macOS M1 HOT 5
- OSR scaling HOT 4
- Browser Focus/TextInput HOT 1
- Dialog box not displaying correctly HOT 6
- Provide a NET8 Package without net6 dependencies HOT 1
- how to change user agent in loaded WebView HOT 1
- [limit] Google: Couldn’t sign you in HOT 1
- Accessibility on the WebView window HOT 19
- Webview doesn't show in Avalonia 11 HOT 3
- The right-clicked menu bar is not displayed correctly on Runtime Identifier "win-x64". HOT 5
- Problems encountered in setting the OsrEnabled parameter HOT 3
- Setting WebView Properties HOT 2
- Cannot input anything in the fields of WebView HOT 6
- No API was found to implement sending messages to the web window HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webview.