Asked  8 Months ago    Answers:  5   Viewed   13 times

I have an ASP.Net application which as desired feature, users would like to be able to take a screenshot. While I know this can be simulated, it would be really great to have a way to take a URL (or the current rendered page), and turn it into an image which can be stored on the server.

Is this crazy? Is there a way to do it? If so, any references?



I can tell you right now that there is no way to do it from inside the browser, nor should there be. Imagine that your page embeds GMail in an iframe. You could then steal a screenshot of the person's GMail inbox!

This could be made safe by having the browser "black out" all iframes and embeds that would violate cross-domain restrictions.

You could certainly write an extension to do this, but be aware of the security considerations outlined above.

Update: You can use a canvas utility function to get a screenshot of a page on the same origin as your code. There's even a lib to allow you to do this:

You can find other possible answers here: Using HTML5/Canvas/JavaScript to take screenshots

Thursday, October 14, 2021

Update: According to it is possible since Cypress 3.3.0 use user-agent property in a cy.request() and cy.visit().

If you need, for example, set userAgent as Googlebot:

cy.visit(url, {
    headers: {
        'user-agent': 'Mozilla/5.0 (compatible; Googlebot/2.1; +',

Original answer before Cypress 3.3.0

before(() => {
    cy.visit(url, {
        onBeforeLoad: win => {
            Object.defineProperty(win.navigator, 'userAgent', {
                value: 'Mozilla/5.0 (compatible; Googlebot/2.1; +',
Friday, July 30, 2021
  • Option 1 - ASP.NET Web Application
  • Option 3 - ASP.NET Core Web Application

Although both project templates use Full .Net Framework, Option 1 is for creating projects using legacy version of ASP.NET MVC in which we can use Global.asax.

Option 3 is totally new concept in which wwwroot folder, using task runners and everything is through OWIN middleware.

A lot of organization and companies are not ready to jump into new project template yet. I believe Option 1 is there for backward compatibility.

Sunday, August 1, 2021

If you need to take a screenshot you will need to do so client side. So you will need to do so using some client side tecnology like javascript, flash, silverlight... runs on the server so it is ruled out.

Here are some links to other related SO questions about taking a screenshot with javascript:

JavaScript code to take a screenshot of a website without using ActiveX

Take a screenshot of a webpage with JavaScript?

Wednesday, August 4, 2021

You can do this without setting custom environment variables. You can do it like this:

if (process.env._ && process.env._.indexOf("heroku"))
   console.log("I'm in Heroku!");

This is possible because on a Heroku dyno the _ environment variable is set to /app/.heroku/node/bin/node.

Sunday, October 31, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :