vmars316 5 Posted November 27, 2020 Report Share Posted November 27, 2020 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') ; } ) ; Quote Link to post Share on other sites
dsonesuk 921 Posted November 27, 2020 Report Share Posted November 27, 2020 https://stackoverflow.com/questions/45639628/how-to-fix-browserwindow-is-not-a-constructor-error-when-creating-child-window-i Quote Link to post Share on other sites
vmars316 5 Posted November 27, 2020 Author Report Share Posted November 27, 2020 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 Quote Link to post Share on other sites
dsonesuk 921 Posted November 27, 2020 Report Share Posted November 27, 2020 Webview? It does not mention webview, what are you looking at? Quote Link to post Share on other sites
vmars316 5 Posted November 29, 2020 Author Report Share Posted November 29, 2020 On 11/27/2020 at 1:10 PM, dsonesuk said: Webview? It does not mention webview, what are you looking at? Yes it is here: ttps://www.electronjs.org/docs/api/webview-tag Quote Link to post Share on other sites
dsonesuk 921 Posted November 30, 2020 Report Share Posted November 30, 2020 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. Quote Link to post Share on other sites
vmars316 5 Posted November 30, 2020 Author Report Share Posted November 30, 2020 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 Quote Link to post Share on other sites
vmars316 5 Posted December 1, 2020 Author Report Share Posted December 1, 2020 Hello; I found exactly what I need here: https://gist.github.com/erickzhao/3f2141be4c6d84c3028742b8998e0f6e Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.