hardkoded / puppeteer-sharp

Headless Chrome .NET API
https://www.puppeteersharp.com
MIT License
3.42k stars 446 forks source link

PuppeteerSharp V19.0.1 ,.NET 8 Exceeded 3000 in release, but works normally in debug #2752

Closed xiazhao001 closed 2 months ago

xiazhao001 commented 2 months ago

image

await new BrowserFetcher().DownloadAsync(); var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true, // Args= new string[] {$"--proxy-server=http://{proxy.Server}:{proxy.Port}/api/SysAuth/Login",$"--proxy-auth={proxy.Account}:{proxy.Password}"} });

var page = await browser.NewPageAsync(); //var authToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjI1LCJBY2NvdW50IjoieHoiLCJSZWFsTmFtZSI6IuWkj-aYrSIsImlhdCI6MTcyNDM5NzExOSwibmJmIjoxNzI0Mzk3MTE5LCJleHAiOjE3MjQ0MjU5MTksImlzcyI6Ik1lZUhlYWx0aCIsImF1ZCI6Ik1lZUhlYWx0aCJ9.SOVnD7v5qKTy_QxlEPlrUyYGteFrOgQ1KJ0K7beLNmQ"; //var headers = new Dictionary<string, string> { { "Authorization", $"Bearer {authToken}" } }; //await page.SetExtraHttpHeadersAsync(headers);

await page.SetUserAgentAsync("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");

var url = "http://10.0.0.220:8080/print?templateCode=Anesthesia&pvId=17145058267845&bizId=17829861829317&surgeryInfoMapRecordConfigId=17829861884229&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjI1LCJBY2NvdW50IjoieHoiLCJSZWFsTmFtZSI6IuWkj-aYrSIsImlhdCI6MTcyNDYzNTY5MCwibmJmIjoxNzI0NjM1NjkwLCJleHAiOjE3MjQ2NjQ0OTAsImlzcyI6Ik1lZUhlYWx0aCIsImF1ZCI6Ik1lZUhlYWx0aCJ9.6q4oQ9FHP2cmzk9quj_BKIg2MAingwlJX8sSLGniEQE"; await page.GoToAsync(url);

await page.WaitForSelectorAsync("#print", new WaitForSelectorOptions() { Visible= true });

var path = Path.Combine(Directory.GetCurrentDirectory(), "baidu.pdf");

PdfOptions pdfOptions = new PdfOptions(); pdfOptions.PrintBackground = true; pdfOptions.Format = PaperFormat.A4; pdfOptions.PreferCSSPageSize = true; pdfOptions.DisplayHeaderFooter = false; pdfOptions.FooterTemplate = "";
pdfOptions.Format = new PuppeteerSharp.Media.PaperFormat(8.27m, 11.69m);
pdfOptions.HeaderTemplate = "";
pdfOptions.Landscape = false;
pdfOptions.MarginOptions = new PuppeteerSharp.Media.MarginOptions() { Bottom = "0px", Left = "0px", Right = "0px", Top = "0px" }; pdfOptions.Scale = 1m;
await page.PdfStreamAsync(pdfOptions);

kblok commented 2 months ago

Please share some code I can run locally.

xiazhao001 commented 2 months ago

Hello, there is an error of "Timeout of 180000 ms exceeded" when deploying in IIS,Google version Win64-127.0.6533.88, PuppeteerSharp V19.0.1

await new BrowserFetcher().DownloadAsync(); var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true, });

var page = await browser.NewPageAsync();

await page.SetUserAgentAsync("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");

var url = "https://www.baidu.com"; await page.GoToAsync(url); var path = Path.Combine(Directory.GetCurrentDirectory(), "test.pdf");

PdfOptions pdfOptions = new PdfOptions(); pdfOptions.PrintBackground = true; pdfOptions.Format = PaperFormat.A4; pdfOptions.PreferCSSPageSize = true; pdfOptions.DisplayHeaderFooter = false; pdfOptions.FooterTemplate = ""; pdfOptions.Format = new PuppeteerSharp.Media.PaperFormat(8.27m, 11.69m); pdfOptions.HeaderTemplate = ""; pdfOptions.Landscape = false; pdfOptions.MarginOptions = new PuppeteerSharp.Media.MarginOptions() { Bottom = "0px", Left = "0px", Right = "0px", Top = "0px" }; pdfOptions.Scale = 1m;

await page.PdfAsync(path, pdfOptions); await browser.CloseAsync();

kblok commented 2 months ago

Folding into #2753