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 ?
Related
sample code:
const browser = await puppeteer.launch({
headless: false,
args: ["--disable-setuid-sandbox","--no-sandbox"],
ignoreDefaultArgs: ["--enable-automation"],
});
const page = await browser.newPage();
await page.goto("http://127.0.0.1:3000/");
amazing appearance!!
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+
Hello I try to make a screenshot with Playwright but I have cookie EU law popup on my screenshots. How can I remove them ?
Here is my browser parameters.
const browser = await playwright.firefox.launch({
headless: true,
firefoxUserPrefs: {
"network.cookie.cookieBehavior": 2
}
});
But it don't work.
Thank for your help.
Use the playwright API to click the element. I'm using the text selector in the example below, but you can use any selector.
const { webkit } = require('playwright');
(async() => {
const browser = await webkit.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://npmjs.com');
await page.click('text=Accept');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
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.
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();
})();