TrevorSundberg / puppeteer-in-electron

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

Load preload.js inside puppeteer-in-electron window #56

Open tushar-ghadge opened 2 years ago

tushar-ghadge commented 2 years ago

I'm facing issue to load preload.js while using puppeteer-in-electron package

Here is the snippet:

const { BrowserWindow, app, protocol, BrowserView } = require("electron");
const pie = require("puppeteer-in-electron");
const puppeteer = require("puppeteer-core");
await pie.initialize(app);

const createWindow = async () => {
 const browserConfig = {
    width: 1200,
    height: 900,
    webPreferences: {
      contextIsolation: true,
      nodeIntegration: true,
      enableRemoteModule: false,
      preload: path.join(__dirname, "preload.js"), // use a preload script
    },
  };

 const window = new BrowserWindow(browserConfig);
 const view = new BrowserView();
 window.addBrowserView(view); 
 const browser = await pie.connect(app, puppeteer);
 await pie.getPage(browser , view).goto(loginUrl);
}
app.on("ready", async () => {
  createWindow();
})