Puppeteer/Nodejs stops running when browser is minimised - javascript

const browser = await puppeteer.launch({headless: false, args: ['--window-size=950,340', '--window-position=970,700']});
const page = await browser.newPage();
const url = "https://www.qimai.cn/rank/index/brand/grossing/device/iphone/country/us/genre/6014/date/" + today;
await page.goto(url, {waitUntil: 'load'});
await page.setViewport({
width: 1200,
height: 1000
});
Right now when I minimise the chronium browser, the script will not run and it will pause there until i reopen the browser. I want it to still be able to work and when its minimised so that I could do my own tasks also.

Related

chromium always shows "about:blank" and stops working on raspberry pi 3A+

on raspberry pi 3A+ chromium always shows "about:blank" and stops working unless I close the tab manually and enable new tab
const puppeteer = require("puppeteer");
async function test() {
const browser = await puppeteer.launch({
headless: false,
executablePath: "chromium-browser",
});
const [page] = await browser.pages();
await page.evaluate(() => window.open("https://www.example.com/"));
const page1 = await browser.newPage();
page.close();
await page1.goto("https://allegro.pl/");
await page1.screenshot({ path: "hello.png" });
await browser.close();
}
test();
enter image description here
try to working code on my raspberry pi 3A+

puppeteer launch is not capturing screen shots in javascript

I am launching puppeteer to take a screen shot of a browser. This is my code
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(filePath);
await page.screenshot({
path: outputPath,
type: "png",
fullPage: true,
omitBackground: true
});
await browser.close();
But it is not working
I have tried this also
const browser = await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser'
});
but the second one is working on live environment but not in local.
both were working few days back on local.
Can somebody help me out ?

How do I take a screenshot of my own deployed website and store it using a button on that website?

I have tried Puppeteer locally and it worked for other websites but mine has a few Iframes and it doesn't capture them.
const { chromium } = require("playwright");
(async () => {
let browser = await chromium.launch();
let page = await browser.newPage();
await page.setViewportSize({ width: 1280, height: 1080 });
await page.goto("https://raddy.dev/blog/build-news-website-with-node-js-express-ejs-wp-rest-api/");
await page.screenshot({ path: `nyt-playwright-chromium.png` });
await browser.close();
})();
How can I capture the Iframes in the screenshot as well? It would be great if I could just press a button on my website and get a full screenshot without any missing parts.

Iframe not loading properly in puppeteer

I am trying to parse a website using puppeteer, everything works well but iframe does not load properly.
This is how it loads
Here is my code
args: [
"--no-sandbox",
],
});
const page = await browser.newPage();
await page.setViewport({ width: 1440, height: 600 })
// await waitForFrame(page);
await page.goto(url, {
waitUntil: 'networkidle2',
timeout: 0,
});
await page.evaluate(({ applicationUrl}: any ) => {
// Here i want to evaluate iframes
})
When i try to log iframes, i don't get the actual iframe link on my parsed website
Also i don't see the iframe tag in parsed website
But When i look into the actual page, i can see the iframe link
and also the iframe tag
Here is the link to actual page which i am trying to parse
https://leza.notion.site/Trade-log-721b1ebb4cc74175abb55408b6f2d0c3
Any help would be highly appreciated
it's lazy loaded
try scrolling around and then wait some for iframe to load, and then get the iframe:
await page.goto(url, {
waitUntil: 'networkidle2',
timeout: 0,
});
await page.evaluate(async() => {
const scroll = document.querySelector('.notion-scroller');
scroll.scrollBy(0, 900);
document.querySelector('.notion-video-block').scrollIntoView();
});
// wait some for iframe to load..
await page.waitFor(5000);
const iframeSelector = 'iframe';
const frameHandle = await page.$(iframeSelector);
const src = await page.evaluate(el => el.src, frameHandle);
console.log(src);

Not able to capture image while generating pdf using puppeteer API

Node- v8.11.1 Headless Chrome
Im trying to generate PDF but somehow the background image is not captured in the PDF.
Below is the code. Any help is appreciated
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: true});
const page = await browser.newPage();
await page.goto('http://54.201.139.151/', {waitUntil : 'networkidle0'});
await page.pdf({path: 'hn40.pdf', printBackground: true, width: '1024px' , height: '768px'});
await browser.close();
})();
Update: page.emulateMedia() is dropped in favor of page.emulateMediaType()
As Rippo mentioned, you require page.emulateMedia("screen") for this to work properly. I have updated your script below, but I changed the page to google for testing.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://google.ca/', {waitUntil : 'networkidle2'});
await page.emulateMedia('screen');
await page.pdf({path: 'hn40.pdf', printBackground: true, width: '1024px' , height: '768px'});
await browser.close();
})();

Categories