我正在尝试在页面加载后将javascript注入文档的头部:

var browserSettings = new BrowserSettings();
browserSettings.FileAccessFromFileUrlsAllowed = true;
browserSettings.UniversalAccessFromFileUrlsAllowed = true;
browserSettings.TextAreaResizeDisabled = true;
var webView= new WebView("about:blank", browserSettings);
webView.EvaluateScript("var script = document.createElement('script')"); // Line 1
webView.EvaluateScript("script.src='http://domain.my/scripts/my.js'");   // Line 2
webView.EvaluateScript("document.body.appendChild(script)");             // Line 3


在评估脚本的第1行和第2行之后,我可以在dev工具中看到script变量。但是当我尝试执行第3行时,我收到了异常:

An unhandled exception of type 'System.StackOverflowException' occurred in CefSharp.dll

我的错误在哪里?

最佳答案

解决方案是使用ExecuteScript而不是EvaluteScript。

10-01 17:43