Jump to content

Type error: BrowserView is not a constructor" ??


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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...