Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
How I can get result of event in browserView?

How I can get result of event in browserView? I have:

browserView.webContents.executeJavaScript('
  let btn = document.createElement("button")
  btn.innerHTML = "Click Me"
  btn.addEventListener("click", function () {
    return "Button is clicked"
  })
  document.body.appendChild(btn)
').then(r=> console.log(r))

What I need to do to get "Button is clicked" after click on button in main process and add to variable?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In my solutions we need preload for browserView:

const browserView = new BrowserView({
            webPreferences: {
                preload: path.join(__dirname, 'preload.js') 
            }
        })

preload.js

const {ipcRenderer} = require('electron')

window.addEventListener('DOMContentLoaded', () => {
  let btn = document.createElement("button")
  btn.innerHTML = "Click Me"
  btn.addEventListener("click", function () {
    ipcRenderer.send('message','button is clicked')
  })
  document.body.appendChild(btn)
})

And... it works! In main proccess with ipcMain.on we received "button is clicked"

about 4 years ago · Juan Pablo Isaza Report

0

Basically you need to have to find a way to call ipcRenderer in the view, ex. ipcRenderer.send('message', 'hi'). And in the main thread, you can do ipcMain.on('message', () => {}).

But for your question, how do you access ipcRenderer? Try

  browserView.webContents.executeJavaScript('
    const { ipcRenderer } = require('electron')
    ipcRenderer.send('message', 'hi')

And in the index.js

const { ipcMain } = require('electron')

ipcMain.on('message', (e, t) => {
  console.log(t)
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!