0

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: enter image description here

I want it like: enter image description here

劉鎮瑲
  • 517
  • 9
  • 20
  • 1
    See one of the [WebBrowser.Navigate()](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.webbrowser.navigate) overloads that allows to specify additional Headers (as a string). You can add `"User-Agent: [Your Desktop User Agent of Choice]"`. Try with the Edge/FireFox UserAgent strings first. See also this one: [How can I get the WebBrowser control to show modern contents?](https://stackoverflow.com/a/38514446/7444103). – Jimi May 01 '19 at 04:02
  • If you want screen size, why not use Screen class? – shingo May 01 '19 at 04:21
  • @Jimi I tried your suggestion but not working. Can you look my update content to give me others suggestions? – 劉鎮瑲 Jun 04 '19 at 08:07
  • @shingo I gave more detail about my problem. Can you help me ? Thanks! – 劉鎮瑲 Jun 04 '19 at 08:10
  • But you still didn't answer my question. – shingo Jun 04 '19 at 08:46
  • @shingo I think it is some error when i using webbrowser. I have no idea about Screen class. Can you give some example about Screen that achieve my goal? Thanks! – 劉鎮瑲 Jun 04 '19 at 08:59

0 Answers0