Open ahsanaasim opened 3 years ago
I have changed the bright.ts file to something like this
// @ts-nocheck
import { contextBridge, ipcRenderer } from 'electron'
import Nightmare from 'nightmare';
// const Nightmare = require('nightmare')
const nightmare = new Nightmare({ electronPath: require('electron'), show: true });
export const api = {
/**
* Here you can expose functions to the renderer process
* so they can interact with the main (electron) side
* without security problems.
*
* The function below can accessed using `window.Main.sayHello`
*/
sendMessage: (message: string) => {
ipcRenderer.send('message', message)
},
/**
* Provide an easier way to listen to events
*/
on: (channel: string, callback: Function) => {
ipcRenderer.on(channel, (_, data) => callback(data))
},
nightmare: (): Nightmare => {
// { electronPath: require('electron'), show: true }
console.log(nightmare)
return nightmare
}
}
contextBridge.exposeInMainWorld('Main', api)
And when I call, console.log(window.Main.nightmare()) I can see an interesting thing... window.Main.nightmare() is not returning everything from nightmarejs.
I have explained the whole thing in this video https://www.loom.com/share/e0fac6e0bcdc4291968e6d03f0f0b9cc
I am using Nightmare.js inside an electron app with the webpack. But when I try to use Nightmare.js I am getting the following error
Here is how I am using Nightmare.js
I am using webpack to preload the following code brige.ts
I posted a question in StackOverflow as well. But didn't get any response. https://stackoverflow.com/questions/68271424/unable-to-use-nightmare-js