I am using Webbrowser to get full screenshot of website. Some of website return phone screen width/height automatically,but i don't want it. Can i get computer screen width/height from any website by setting Webbrowser attributes? Is it possible?
I have searched many information on google and this site, but none of them were solve my question. The code below is how far I've tried.
WebBrowser browser = sender as WebBrowser;
browser.ScrollBarsEnabled = false;
browser.Width = browser.Document.Body.ScrollRectangle.Width;
browser.Height = browser.Document.Body.ScrollRectangle.Height;
using (Bitmap bitmap = new Bitmap(browser.Width, browser.Height))
{
browser.DrawToBitmap(bitmap, new Rectangle(0, 0, browser.Width, browser.Height));
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
byte[] bytes = stream.ToArray();
Image1.Visible = true;
Image1.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes);
}
}
In this website 1 I got the size exactly what i saw in computer,but I get phone size width/height return from Webbrowser of this website 2.
Any tips or suggestions is meaningful for me.Thanks!
Update:
I tried the suggestion at comment area like this:
browser.Navigate(url, "_self", null, "User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
After document complete I try to get browser.Document.Body.ScrollRectangle.Width browser.Document.Body.ScrollRectangle.Height
and I got the width which isn't what i want like below picture: