TrevorSundberg / puppeteer-in-electron

Use puppeteer to test and control your electron application.
MIT License
342 stars 51 forks source link

Using the code in readme.md returns an error #36

Closed Rohaanpk closed 3 years ago

Rohaanpk commented 3 years ago

Using the code in readme.md returns the following error: (node:7952) UnhandledPromiseRejectionWarning: Error: The parameter 'app' was not passed in. This may indicate that you are running in node rather than electron.

I am very new to puppeteer, js and electron so I am unsure why this is happening. This error occurs with and without adding a semicolon on the second line (const pie = require("puppeteer-in-electron"))

const {BrowserWindow, app} = require("electron");
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();
    const url = "https://example.com/";
    await window.loadURL(url);

    const page = await pie.getPage(browser, window);
    console.log(page.url());
    window.destroy();
};

main();
Rohaanpk commented 3 years ago

This was due to an error on my end, was running the code via "node index", not "electron index"