PuppeteerSharp V19.0.1 ,.NET 8 Exceeded 3000 in release, but works normally in debug
xiazhao001 opened this issue · 3 comments
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");
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);
Please share some code I can run locally.
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();