Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke Chrome Node Screenshot from the console?

I know you can capture a single html node vial the command prompt, but is it possible to do this programmatically from the console similar to Puppeteer? I'd like to loop all elements on a page and capture them for occasional one-off projects where I don't want to set up a full auth process in puppeteer.

I'm referring to this functionality:

enter image description here

But executed from the console like during a foreach or something like that.

See the puppeteer reference here.

Something to the effect of this:

$x("//*[contains(@class, 'special-class-name')]").forEach((el)=> el.screenshot())
like image 522
motleydev Avatar asked Jun 06 '18 08:06

motleydev


People also ask

How do you screenshot on a developer console?

Click on the 3 lines on top right corner on the browser window >> Web Developer >> Web Console. Alternatively, you can also press Ctrl+Shift+K (Windows) or Cmd+Opt+K (Mac) from keyboard. You need to first enable the developer menu to access web inspector on Safari. Choose Safari > Preferences, and click Advanced.

What is capture node screenshot Chrome?

Capture node screenshot - Captures a screenshot of the inspected element in isolation. Capture screenshot - Captures a screenshot of the viewport only. Capture full size screenshot - Captures the entire page, even what is outside of the visible viewport.


1 Answers

I just made a script that take a screenshot every submit button in Google main page. Just take a look and take some inspiration from it.

const puppeteer = require('puppeteer')

;(async () => {
    const browser = await puppeteer.launch({
        headless:false,
        defaultViewport:null,
        devtools: true,
        args: ['--window-size=1920,1170','--window-position=0,0']
    })

    const page = (await browser.pages())[0]

    const open = await page.goto ( 'https://www.google.com' )

    const submit = await page.$$('input[type="submit"]')

    const length = submit.length

    let num = 0

    const shot = submit.forEach( async elemHandle => {
        num++
        await elemHandle.screenshot({
            path : `${Date.now()}_${num}.png`
        })
    })

})()
like image 67
Edi Imanto Avatar answered Oct 17 '22 07:10

Edi Imanto