Closed Majid1512 closed 3 years ago
Change this:
await window.loadURL(url);
To this:
await page.goto(url);
What worked for me was to do exactly like the previous code
True
const pie = require("puppeteer-in-electron")
const puppeteer = require("puppeteer-core");
const main = async () => {
await pie.initialize(app);
const browser = await pie.connect(app, puppeteer);
const window = new BrowserWindow({show: true});
const url = "https://instagram.com";
await window.loadURL(url);
const page = await pie.getPage(browser, window);
await page.screenshot({path: 'example1.png'});
};
main();
False
const pie = require("puppeteer-in-electron")
const puppeteer = require("puppeteer-core");
const main = async () => {
await pie.initialize(app);
const browser = await pie.connect(app, puppeteer);
const window = new BrowserWindow({show: false});
const url = "https://instagram.com";
await window.loadURL(url);
const page = await pie.getPage(browser, window);
await page.screenshot({path: 'example1.png'});
};
main();
It would appear electron does not have a proper headless mode, and as you discovered if you use new BrowserWindow({show: false})
then the page.screenshot
will hang. @Slayde1r solution works and await page.goto(url)
works in this case however I have not tested it for more complex scenarios.
The advised way for doing "headless" operations on electron is to use Xvfb to wrap your application: https://www.electronjs.org/docs/tutorial/testing-on-headless-ci
Thank you for your very useful module. I'm using it to make use of puppeteer without additionally needing to download chromium. However, I'm having some trouble when doing the webautomation headlessly.
The following code works as expected and produces a .png:
I tried making this task headless by setting the show parameter of BrowserWindow to false:
Now no browserwindow pops up, but no screenshot is being produced.
I wonder how to make the webautomation to work headlessly with this module.