Browser automation (Puppeteer) don't working properly (net core 6)

101 Views Asked by At

I use PuppeteerSharp and PuppeteerExtraSharp library, it seems this pattern was worked properly in my past project, but currently i can not start it. This is my page factory, I expect 25 Chrome tabs.

Public Async Function EmptyPagesFactoryAsync(ByVal count As Integer) As Task(Of List(Of Page))
    Dim Pages As List(Of Page) = New List(Of Page)
    For i As Integer = 0 To count - 1
        Try
            ProxyCounter = (ProxyCounter + 1) Mod Proxys.Count
            Dim Proxy = Proxys(ProxyCounter)
            Dim ProxyURL = Proxy.Split("@")(1)
            Dim Extra = New PuppeteerExtraSharp.PuppeteerExtra
            Dim Browser = Await Extra.LaunchAsync(New PuppeteerSharp.LaunchOptions With {
                .Headless = False,
                .ExecutablePath = _config.GetSection("ChromePath").Value,
                .Args = New String() {$"--proxy-server={ProxyURL}"}
            })
            Dim BrowserCredentials = New Credentials With {
                .Username = Proxy.Split("@")(0).Split(":")(0),
                .Password = Proxy.Split("@")(0).Split(":")(1)
            }
            Dim PageTask = Await Browser.NewPageAsync
            Await PageTask.AuthenticateAsync(BrowserCredentials)
            Dim cookies = JsonConvert.DeserializeObject(Of CookieParam)(File.ReadAllText("cookies.txt"))
            Await PageTask.SetCookieAsync(cookies)
            Pages.Add(PageTask)
            Browsers.Add(Browser)
        Catch ex As Exception
            _log.LogCritical(ex.Message & vbCrLf & ex.StackTrace)
        End Try
    Next
    Return Pages
End Function

Proxy file read correctly, I'm sure. And proxies list is workable, because I use the same list in my other project based on TheArtOfDev automation, this means url and login/pass is correct. Chrome path also setting correctly, parameter also setting correctly --proxy-server==xx.xx.xx.xx:yyy. There are no any exception, but maybe I doing something wrong, because I see only one blank Chrome page after line "Dim Browser", than program stopped and line "Dim BrowserCredentials" never working.
Where is my mistake?

Interesting, if I downgrade PuppeteerSharp from last version to 7.10 and PuppeteerExtraSharp to 1.3.2 I receive another error in class AsyncMethodBuilderCore

AsyncMethodBuilderCore Error

But this error appears only in ancient version, new version has another issue.

0

There are 0 best solutions below