vmars316 Posted November 27, 2020 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') ; } ) ; Link to comment Share on other sites More sharing options...
dsonesuk Posted November 27, 2020 Share Posted November 27, 2020 https://stackoverflow.com/questions/45639628/how-to-fix-browserwindow-is-not-a-constructor-error-when-creating-child-window-i Link to comment Share on other sites More sharing options...
vmars316 Posted November 27, 2020 Author 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted November 27, 2020 Share Posted November 27, 2020 Webview? It does not mention webview, what are you looking at? Link to comment Share on other sites More sharing options...
vmars316 Posted November 29, 2020 Author 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted November 30, 2020 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. Link to comment Share on other sites More sharing options...
vmars316 Posted November 30, 2020 Author 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 Link to comment Share on other sites More sharing options...
vmars316 Posted December 1, 2020 Author Share Posted December 1, 2020 Hello; I found exactly what I need here: https://gist.github.com/erickzhao/3f2141be4c6d84c3028742b8998e0f6e Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now