Jump to content

Type error: BrowserView is not a constructor" ??


vmars316
 Share

Recommended Posts

Hello;

I am getting error: "Uncaught exception: Type error: BrowserView is not a constructor" ?? 

on this line: 

const view = new BrowserView( ) ; 

in code below ;

I can't figure out why , because the line above is basically the same: 

const win = new BrowserWindow( {width: 600, height: 600, webPreferences: {nodeIntegration: true} 
})

Thanks

const { BrowserView, BrowserWindow } = require('electron') ;

app.on('ready', function() {
const win = new BrowserWindow( {width: 600, height: 600, webPreferences: {nodeIntegration: true} 
}) ;
const view = new BrowserView( ) ; // {width: 350, height: 350, webPreferences: {nodeIntegration: true}

win.setBrowserView(view) ;
win.webContents.loadURL("file:///C:/Electron-js/~~KidSafeBrowser-RESTART/index.html") ;
win.webContents.openDevTools()   // works in same window 
view.setBounds({ x: 10, y: 40, width: 750 , height: 500 }) ;
view.webContents.loadURL('http://vmars.us/KidSafeBrowser/SafeBrowserHome.html') ;
} ) ;


 

Link to comment
Share on other sites

  • vmars316 changed the title to Type error: BrowserView is not a constructor" ??

Thanks dsonesuk  ;

I am using BrowserView not webview ,

and I am doing it in main.js , not in renderer.js .  

https://www.electronjs.org/docs/api/webview-tag
Recommends not using webview any more .

This is the recommended way: 
https://www.electronjs.org/docs/api/browser-view 

My whole main.js code:

const electron = require("electron") ;
const app = electron.app ;
const path = require('path') ;
const url = require('url') ;
const { BrowserView, BrowserWindow } = require('electron') ;

app.on('ready', function() {
const win = new BrowserWindow( {width: 600, height: 600, webPreferences: {nodeIntegration: true} 
}) ;
const view = new BrowserView( ) ; // {width: 350, height: 350, webPreferences: {nodeIntegration: true}

win.setBrowserView(view) ;
win.webContents.loadURL("file:///C:/Electron-js/~~KidSafeBrowser-RESTART/index.html") ;
win.webContents.openDevTools()   // works in same window 
view.setBounds({ x: 10, y: 40, width: 750 , height: 500 }) ;
view.webContents.loadURL('http://vmars.us/KidSafeBrowser/SafeBrowserHome.html') ;
} ) ;

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', () => {
  if (browserwindow.getAllWindows().length === 0) {
    createWindow()
  }
})
// _dirname Example:    win.loadURL(file://${__dirname}/index.html)
//view.webContents.openDevTools()   // works but in a separate window 

 

Link to comment
Share on other sites

Which is totally unrelated to the link provided, which explains why you get this error mainly for browserview but also mentions webview.

You are introducing a new conversation on a subject that was not mentioned, not referred too, with no reason to mention. The issue was with browserview, the link was how go about fixing that issue.

Link to comment
Share on other sites

14 hours ago, dsonesuk said:

Which is totally unrelated to the link provided, which explains why you get this error mainly for browserview but also mentions webview.

You are introducing a new conversation on a subject that was not mentioned, not referred too, with no reason to mention. The issue was with browserview, the link was how go about fixing that issue.

I am not using:

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process
Ask Question. So it is not pertinent to me .

I gave these links , just in case you are not proficient with webview/BrowserView in Electron , to give you some context for this question .

https://www.electronjs.org/docs/api/webview-tag
Recommends not using webview any more .

This is the recommended way: 
https://www.electronjs.org/docs/api/browser-view 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...