Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WebView2 - Edge can't access Program Files
#1
Hi, I'm trying to run the example for WebView2 from the Cookbook.  I get this error:
Quote:We couldn't create the data directory

Microsoft Edge can't read and write to its data directory:

        C:\Program Files\LibreAutomate\Au.Task.exe.WebView2\EBWebView

I've tried changing the cache directory with the code commented out in the code box below, but when I uncomment those lines I get the following error:
Quote:System.InvalidOperationException: EnsureCoreWebView2Async cannot be used before the application's event loop has started running.
 
Code:
Copy      Help
/*/ nuget -\Microsoft.Web.WebView2; /*/

using Microsoft.Web.WebView2.Wpf;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Web.WebView2.Core;

var b = new wpfBuilder("Window").WinSize(700, 600);

//var env = await CoreWebView2Environment.CreateAsync(null, @"C:\Temp", null);
b.Row(-1).Add(out WebView2 k);
k.Source = new("https://www.google.com");
b.R.AddSeparator();
b.R.AddOkCancel();
b.End();
//await k.EnsureCoreWebView2Async(env);
if (!b.ShowDialog()) return;
I've tried placing the offending line most places in the script, but I always get the 'event loop' error.

Thanks very much for your help!
Regards,
burque505
#2
Code:
Copy      Help
// script ""
/*/ nuget -\Microsoft.Web.WebView2; /*/

using Microsoft.Web.WebView2.Wpf;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Web.WebView2.Core;

var b = new wpfBuilder("Window").WinSize(700, 600);
b.Row(-1).Add(out WebView2 k);
b.R.AddSeparator();
b.R.AddOkCancel();
b.End();

b.Loaded += () => {
    var env = CoreWebView2Environment.CreateAsync(null, @"C:\Temp", null).Result;
    k.EnsureCoreWebView2Async(env);
    k.Source = new("https://www.google.com");
};


if (!b.ShowDialog()) return;

Or in script Properties select role exeProgram.
#3
Thank you! That works great. By the way, I didn't see this post before I tried another route, which also worked, but is probably a bad idea: I gave CREATOR OWNER write access to 'C:\Program Files\LibreAutomate\Au.Task.exe.WebView2', and the error in the Cookbook example (verbatim) disappeared.

Best regards, and thank you for LA!
burque505


Forum Jump:


Users browsing this thread: 2 Guest(s)