Cannot use module Puppeteer in electron

Viewed 224

Problem

I cannot understand how to use Puppeteer in Electron NPM module. I copied the code from the npm page and tried to run it but gives the following error:

Error: The parameter 'app' was not passed in. This may indicate that you are running in node rather than electron

Objective

My objective is to execute the script on the press of a button (in headless mode).

Code


//api/test.js


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://google.com/";
  await window.loadURL(url);
 
  const page = await pie.getPage(browser, window);
  console.log(page.url());
  window.destroy();
};

module.exports = main;
//HTML script

const main = require("../test");

document.getElementById('startButton').addEventListener('click', runScript)

function runScript(){
   main()
}
0 Answers
Related