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
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.
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.
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With