Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PuppeteerSharp in LA
#1
The following code can be executed successfully in LinqPad, but cannot open the webpage in LA

Code:
Copy      Help
/*/ nuget Pts\PuppeteerSharp; /*/

using PuppeteerSharp;

Environment.CurrentDirectory = @"C:\Users\Administrator\Desktop";

static async void DoScreenshot(string url)
{

    using var browserFetcher = new BrowserFetcher();
    await browserFetcher.DownloadAsync();
    await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
    {
        Headless = false,
        UserDataDir = @$"{folders.Temp}\chrome\UserData"
    });
    
    await using var page = await browser.NewPageAsync();
    await page.SetViewportAsync(new ViewPortOptions
    {
        Width = 1920,
        Height = 1080
    });
    await page.GoToAsync(url);
    await page.ScreenshotAsync("test.jpg");
    await browser.CloseAsync();
}

DoScreenshot("https://www.libreautomate.com/");
#2
DoScreenshot, being async, returns when started await. The caller does not await it, therefore the process exits.

Simplified example. Incorrect.
 
Code:
Copy      Help
static async void DoScreenshot(string url) {
    await Task.Run(() => { dialog.show("task"); });

}

DoScreenshot("https://www.libreautomate.com/");

Correct.
 
Code:
Copy      Help
static async Task DoScreenshot(string url) {
    await Task.Run(() => { dialog.show("task"); });

}

await DoScreenshot("https://www.libreautomate.com/");
#3
thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)