I'm testing out puppeteer for chrome browser automation ( previously using selenium but had a few headaches with browser not waiting until page fully loaded ) .
When I launch an instance of puppeteer - then it displays the contents taking up less than half the screen with scroll bars. How can I make it take up a full screen?
const puppeteer = require('puppeteer'); async function test(){ const browser = await puppeteer.launch({ headless: false, }); const page = await browser.newPage(); await page.goto('http://google.com') } test()
The initial page seems to load fine , but as soon as I access a page it makes it scrollable and smaller.
Chrome arguments are passed to the puppeteer. launch function as the values of the key args , and not rgs . Also, in your Chrome configuration, I suspect that the flags --start-fullscreen and --window-size are contradictory. Finally, you might be interested in the Chrome flag --start-maximized .
You can pass the --window-size flag as an argument to puppeteer. launch() to change the window size to your desired width and height . Then you can call the Chrome Devtools Protocol method Emulation. clearDeviceMetricsOverride to clear the overridden device metrics (including the default 800 x 600 viewport).
You probably would want to set a certain screen size, which any real browser has:
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setViewport({ width: 1366, height: 768}); await page.goto('https://example.com', {waitUntil: 'networkidle2'}); await page.screenshot({path: 'example.png'}); browser.close(); })();
you can user options in launch
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({ args:[ '--start-maximized' // you can also use '--start-fullscreen' ] }); const page = await browser.newPage(); await page.setViewport({ width: 1366, height: 768}); await page.goto('https://example.com', {waitUntil: 'networkidle2'}); await page.screenshot({path: 'example.png'}); browser.close(); })();
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