---
id: "M:cAlgo.API.WebView.ExecuteScriptAsync(System.String)"
kind: "method"
type: "T:cAlgo.API.WebView"
url: "https://help.ctrader.com/ctrader-algo/references/Controls/WebView/ExecuteScriptAsync/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# WebView.ExecuteScriptAsync

Member of [WebView](https://help.ctrader.com/ctrader-algo/references/Controls/WebView/index.md).

## ExecuteScriptAsync(string javaScript)

Executes JavaScript code from the javaScript parameter in the current top level document rendered in the WebView. You can only use this method after control is fully loaded and navigation is completed.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: Accepted without error but never displayed, so control events such as Click are never raised.
- Cloud: Accepted without error but never displayed, so control events such as Click are never raised.

C#:

```csharp
public void ExecuteScriptAsync(string javaScript)
```

Python:

```python
webView.ExecuteScriptAsync(javaScript: str) -> None
```

### Parameters

- `javaScript` (`string`, Python `str`): JavaScript code

### Examples

C#:

```csharp
var webView = new WebView { Width = 300, Height = 100 };
webView.NavigateToStringAsync("<html><body id='price'></body></html>");
webView.NavigationCompleted += args => webView.ExecuteScriptAsync("document.getElementById('price').innerText = '" + Symbol.Bid + "'");
Chart.AddControl(webView);
```

Python:

```python
webView = WebView()
webView.Width = 300
webView.Height = 100
webView.NavigateToStringAsync("<html><body id='price'></body></html>")
webView.NavigationCompleted += lambda args: webView.ExecuteScriptAsync(f"document.getElementById('price').innerText = '{api.Symbol.Bid}'")
api.Chart.AddControl(webView)
```

## ExecuteScriptAsync(string javaScript, Action<ExecuteScriptResult> callback)

Executes asynchronously JavaScript code from the javaScript parameter in the current top level document rendered in the WebView. You can only use this method after control is fully loaded and navigation is completed.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: Accepted without error but never displayed, so control events such as Click are never raised.
- Cloud: Accepted without error but never displayed, so control events such as Click are never raised.

C#:

```csharp
public void ExecuteScriptAsync(string javaScript, Action<ExecuteScriptResult> callback)
```

Python:

```python
webView.ExecuteScriptAsync(javaScript: str, callback: Callable[[ExecuteScriptResult], None]) -> None
```

### Parameters

- `javaScript` (`string`, Python `str`): JavaScript code
- `callback` (`Action<ExecuteScriptResult>`, Python `Callable[[ExecuteScriptResult], None]`): The callback that will be called after execution finished

### Examples

C#:

```csharp
var webView = new WebView { Width = 300, Height = 100 };
webView.NavigateToStringAsync("<html><body>Hello</body></html>");
webView.NavigationCompleted += args => webView.ExecuteScriptAsync("document.body.innerText", result => Print("Successful: {0}, JSON: {1}", result.IsSuccessful, result.Json));
Chart.AddControl(webView);
```

Python:

```python
webView = WebView()
webView.Width = 300
webView.Height = 100
webView.NavigateToStringAsync("<html><body>Hello</body></html>")
webView.NavigationCompleted += lambda args: webView.ExecuteScriptAsync("document.body.innerText", lambda result: api.Print(f"Successful: {result.IsSuccessful}, JSON: {result.Json}"))
api.Chart.AddControl(webView)
```

