Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to to take a screenshot of an iframe in a web page?

I'm trying to take a screenshot of an iframe in a webpage. In my particular case, the iframe contains the Street View of one of my clients' store. As far as I've searched and read, I didn't find any solution to this.

I know there are JavaScript libraries like Html2Canvas and Canvas2Image, but they are not able to capture an iframe.

Here is the fiddle I'm working on that.

These libraries are working properly with every HTML element, except the iframe.

This is the JavaScript of the fiddle:

$(function() { 
        $("#btnSave").click(function() { 
        html2canvas($("#widget"), {
            onrendered: function(canvas) {
                var context=canvas.getContext("2d"); // returns the 2d context object
                // Convert and download as image 
                theCanvas = canvas;
                document.body.appendChild(canvas);

                // Convert and download as image 
                Canvas2Image.saveAsPNG(canvas); 
                $("#img-out").append(canvas);
            }
        });
    });
});

Does any other way to capture an iframe exist? Are there any paid third-party services that can do this?

If nothing will work with an iframe, are there any alternatives to achieve what I'm trying to do?

Please tell me if more informations are needed.

Any help will be greatly appreciated.

Thanks in advance

like image 659
eccebombo Avatar asked Jun 11 '19 12:06

eccebombo


People also ask

Is there a way to take a screenshot of an entire webpage?

Also, you can press Ctrl+Shift+P on Windows or Command+Shift+P on Mac. Type screenshot into the search box. Select Capture full-size screenshot. Once Chrome takes the screenshot, it should save it into your Downloads folder.

How do I take a screenshot of a HTML page?

Please click on the toolbar button (or press Alt+Shift+D combination) to capture the screenshot. You can adjust the screenshot image format from the options page.

How do you take a screenshot of a whole page using inspect?

Control-click anywhere on a page you want to capture and choose Inspect. Press Command-Shift-P to open Chrome's Developer Tools command menu. Type “capture” and then click “Capture full size screenshot” to download a screenshot of the page as a PNG file.

How do I take a screenshot of a whole web page in Windows?

Open the webpage you want to capture, then press and hold “Ctrl” + “Alt.” Then, press the “Prtsc” key. Left-click on the corner of the red highlighted box and drag to select the screenshot area.


1 Answers

If you need to do the capture in a programmed way, you have the option of using nodejs with puppeteer which is a library that uses chromium to simulate a web browser. I give you an example to capture the screen:

const puppeteer = require('puppeteer');

async function run() {
    let browser = await puppeteer.launch({ headless: false });
    let page = await browser.newPage();
    await page.goto('https://www.scrapehero.com/');
    await page.screenshot({ path: './image.jpg', type: 'jpeg' });
    await page.close();
    await browser.close();
}

run();

Here is the source where I got it from: https://www.scrapehero.com/how-to-take-screenshots-of-a-web-page-using-puppeteer/

like image 183
Diego Alfayate Avatar answered Nov 14 '22 21:11

Diego Alfayate