You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I agree to follow the Code of Conduct that this project adheres to.
I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
30.0.1
What operating system are you using?
Windows
Operating System Version
Windows 11 23H2
What arch are you using?
x64
Last Known Working Electron version
30.0.1
Expected Behavior
when i switch these lines of my diolog code below i get weird funkey rendering glitches like when i try and open cotext menus or hover over my objects i get weird gray boxes and then my app crashes when i try to make a new tab and i have tried properly initializing and that dident work ither
here are both of the diolog classes with the BrowserView even tho its depricated but i no longer have the WebContentsView version everty since iv had this issue
what im expecting is for all the diologs to show properly, with no gray boxes, and for the app to stop crashing when i try to do somethign e. g creating a new tab
diolog-service.ts
import{BrowserView,app,ipcMain}from'electron';import{join}from'path';import{SearchDialog}from'../dialogs/search';import{PreviewDialog}from'../dialogs/preview';import{PersistentDialog}from'../dialogs/dialog';import{Application}from'../application';import{IRectangle}from'~/interfaces';interfaceIDialogTabAssociation{tabId?: number;getTabInfo?: (tabId: number)=>any;setTabInfo?: (tabId: number, ...args: any[])=>void;}typeBoundsDisposition='move'|'resize';interfaceIDialogShowOptions{name: string;browserWindow: Electron.BrowserWindow;hideTimeout?: number;devtools?: boolean;tabAssociation?: IDialogTabAssociation;onWindowBoundsUpdate?: (disposition: BoundsDisposition)=>void;onHide?: (dialog: IDialog)=>void;getBounds: ()=>IRectangle;}interfaceIDialog{setBounds: any;show: any;once: any;webContents: any;name: string;// NOTEL: some parts of my code still need this refrence to BrowserView, because as of now, electron hasent fully// moved all functionallity to the new WebContentsView yet. So we still need to use BrowserView in some places.// NOTICE: electron has BrowserView Classafied as a Wrapper around the new WebContentsView so its still relavent for now.browserView: BrowserView;webContentsView: Webid: number;tabIds: number[];_sendTabInfo: (tabId: number)=>void;hide: (tabId?: number)=>void;handle: (name: string,cb: (...args: any[])=>any)=>void;on: (name: string,cb: (...args: any[])=>any)=>void;rearrange: (bounds?: IRectangle)=>void;}exportconstroundifyRectangle=(rect: IRectangle): IRectangle=>{constnewRect: any={ ...rect};Object.keys(newRect).forEach((key)=>{if(!isNaN(newRect[key]))newRect[key]=Math.round(newRect[key]);});returnnewRect;};exportclassDialogsService{publicbrowserViews: BrowserView[]=[];publicbrowserViewDetails=newMap<number,boolean>();publicwebContentsViewDetails=newMap<number,boolean>();publicdialogs: IDialog[]=[];publicpersistentDialogs: PersistentDialog[]=[];publicrun(){this.createBrowserView();this.persistentDialogs.push(newSearchDialog());this.persistentDialogs.push(newPreviewDialog());}privatecreateBrowserView(){constview=newBrowserView({webPreferences: {nodeIntegration: true,contextIsolation: false,webviewTag: true,//worldSafeExecuteJavaScript: false,},});require('@electron/remote/main').enable(view.webContents);view.webContents.loadURL(`about:blank`);this.browserViews.push(view);this.browserViewDetails.set(view.webContents.id,false);returnview;}publicshow(options: IDialogShowOptions): IDialog{const{
name,
browserWindow,
getBounds,
devtools,
onHide,
hideTimeout,
onWindowBoundsUpdate,
tabAssociation,}=options;constfoundDialog=this.getDynamic(name);letbrowserView=foundDialog
? foundDialog.browserView
: this.browserViews.find((x)=>!this.browserViewDetails.get(x.webContents.id),);if(!browserView){browserView=this.createBrowserView();}constappWindow=Application.instance.windows.fromBrowserWindow(browserWindow);if(foundDialog&&tabAssociation){foundDialog.tabIds.push(tabAssociation.tabId);foundDialog._sendTabInfo(tabAssociation.tabId);}browserWindow.webContents.send('dialog-visibility-change',name,true);this.browserViewDetails.set(browserView.webContents.id,true);if(foundDialog){browserWindow.addBrowserView(browserView);foundDialog.rearrange();returnnull;}browserWindow.addBrowserView(browserView);browserView.setBounds({x: 0,y: 0,width: 1,height: 1});if(devtools){browserView.webContents.openDevTools({mode: 'detach'});}consttabsEvents: {activate?: (id: number)=>void;remove?: (id: number)=>void;}={};constwindowEvents: {resize?: ()=>void;move?: ()=>void;}={};constchannels: string[]=[];constdialog: IDialog={
browserView,id: browserView.webContents.id,
name,tabIds: [tabAssociation?.tabId],_sendTabInfo: (tabId)=>{if(tabAssociation.getTabInfo){constdata=tabAssociation.getTabInfo(tabId);browserView.webContents.send('update-tab-info',tabId,data);}},hide: (tabId)=>{const{ selectedId }=appWindow.viewManager;dialog.tabIds=dialog.tabIds.filter((x)=>x!==(tabId||selectedId),);if(tabId&&tabId!==selectedId)return;browserWindow.webContents.send('dialog-visibility-change',name,false);browserWindow.removeBrowserView(browserView);if(tabAssociation&&dialog.tabIds.length>0)return;ipcMain.removeAllListeners(`hide-${browserView.webContents.id}`);channels.forEach((x)=>{ipcMain.removeHandler(x);ipcMain.removeAllListeners(x);});this.dialogs=this.dialogs.filter((x)=>x.id!==dialog.id);this.browserViewDetails.set(browserView.webContents.id,false);if(this.browserViews.length>1){// TODO: garbage collect unused BrowserViews?// this.browserViewDetails.delete(browserView.id);// browserView.destroy();// this.browserViews.splice(1, 1);}else{browserView.webContents.loadURL('about:blank');}if(tabAssociation){appWindow.viewManager.off('activated',tabsEvents.activate);appWindow.viewManager.off('removed',tabsEvents.remove);}browserWindow.removeListener('resize',windowEvents.resize);browserWindow.removeListener('move',windowEvents.move);if(onHide)onHide(dialog);},handle: (name,cb)=>{constchannel=`${name}-${browserView.webContents.id}`;ipcMain.handle(channel,(...args)=>cb(...args));channels.push(channel);},on: (name,cb)=>{constchannel=`${name}-${browserView.webContents.id}`;ipcMain.on(channel,(...args)=>cb(...args));channels.push(channel);},rearrange: (rect)=>{rect=rect||{};browserView.setBounds({x: 0,y: 0,width: 0,height: 0,
...roundifyRectangle(getBounds()),
...roundifyRectangle(rect),});},};tabsEvents.activate=(id)=>{constvisible=dialog.tabIds.includes(id);browserWindow.webContents.send('dialog-visibility-change',name,visible);if(visible){dialog._sendTabInfo(id);browserWindow.removeBrowserView(browserView);browserWindow.addBrowserView(browserView);}else{browserWindow.removeBrowserView(browserView);}};tabsEvents.remove=(id)=>{dialog.hide(id);};constemitWindowBoundsUpdate=(type: BoundsDisposition)=>{if(tabAssociation&&!dialog.tabIds.includes(appWindow.viewManager.selectedId)){onWindowBoundsUpdate(type);}};windowEvents.move=()=>{emitWindowBoundsUpdate('move');};windowEvents.resize=()=>{emitWindowBoundsUpdate('resize');};if(tabAssociation){appWindow.viewManager.on('removed',tabsEvents.remove);appWindow.viewManager.on('activated',tabsEvents.activate);}if(onWindowBoundsUpdate){browserWindow.on('resize',windowEvents.resize);browserWindow.on('move',windowEvents.move);}browserView.webContents.once('dom-ready',()=>{dialog.rearrange();browserView.webContents.focus();});if(process.env.NODE_ENV==='development'){browserView.webContents.loadURL(`http://localhost:4444/${name}.html`);}else{browserView.webContents.loadURL(join('file://',app.getAppPath(),`build/${name}.html`),);}ipcMain.on(`hide-${browserView.webContents.id}`,()=>{dialog.hide();});if(tabAssociation){dialog.on('loaded',()=>{dialog._sendTabInfo(tabAssociation.tabId);});if(tabAssociation.setTabInfo){dialog.on('update-tab-info',(e,tabId, ...args)=>{tabAssociation.setTabInfo(tabId, ...args);});}}this.dialogs.push(dialog);returndialog;}publicgetBrowserViews=()=>{returnthis.browserViews.concat(Array.from(this.persistentDialogs).map((x)=>x.browserView),);};publicdestroy=()=>{this.getBrowserViews().forEach((x)=>(x.webContentsasany).destroy());};publicsendToAll=(channel: string, ...args: any[])=>{this.getBrowserViews().forEach((x)=>!x.webContents.isDestroyed()&&x.webContents.send(channel, ...args),);};publicget(name: string){returnthis.getDynamic(name)||this.getPersistent(name);}publicgetDynamic(name: string){returnthis.dialogs.find((x)=>x.name===name);}publicgetPersistent(name: string){returnthis.persistentDialogs.find((x)=>x.name===name);}publicisVisible=(name: string)=>{returnthis.getDynamic(name)||this.getPersistent(name)?.visible;};}
diolog.ts
import{BrowserView,WebContentsView,app,ipcMain,BrowserWindow}from'electron';import{join}from'path';import{roundifyRectangle}from'../services/dialogs-service';interfaceIOptions{name: string;devtools?: boolean;bounds?: IRectangle;hideTimeout?: number;customHide?: boolean;webPreferences?: Electron.WebPreferences;}interfaceIRectangle{x?: number;y?: number;width?: number;height?: number;}exportclassPersistentDialog{publicbrowserWindow: BrowserWindow;// NOTEL: some parts of my code still need this refrence to BrowserView, because as of now, electron hasent fully// moved all functionallity to the new WebContentsView yet. So we still need to use BrowserView in some places.// NOTICE: electron has BrowserView Classafied as a Wrapper around the new WebContentsView so its still relavent for now.publicbrowserView: BrowserView;publicwebContentsView: WebContentsView;publicvisible=false;publicbounds: IRectangle={x: 0,y: 0,width: 0,height: 0,};publicname: string;privatetimeout: any;privatehideTimeout: number;privateloaded=false;privateshowCallback: any=null;publicconstructor({
bounds,
name,
devtools,
hideTimeout,
webPreferences,}: IOptions){this.browserView=newBrowserView({webPreferences: {nodeIntegration: true,contextIsolation: false,//worldSafeExecuteJavaScript: false,
...webPreferences,},});this.bounds={ ...this.bounds, ...bounds};this.hideTimeout=hideTimeout;this.name=name;const{ webContents }=this.browserView;require('@electron/remote/main').enable(webContents);ipcMain.on(`hide-${webContents.id}`,()=>{this.hide(false,false);});webContents.once('dom-ready',()=>{this.loaded=true;if(this.showCallback){this.showCallback();this.showCallback=null;}});if(process.env.NODE_ENV==='development'){this.webContents.loadURL(`http://localhost:4444/${this.name}.html`);}else{this.webContents.loadURL(join('file://',app.getAppPath(),`build/${this.name}.html`),);}}publicgetwebContents(){returnthis.browserView.webContents;}publicgetid(){returnthis.webContents.id;}publicrearrange(rect: IRectangle={}){this.bounds=roundifyRectangle({height: rect.height||this.bounds.height||0,width: rect.width||this.bounds.width||0,x: rect.x||this.bounds.x||0,y: rect.y||this.bounds.y||0,});if(this.visible){this.browserView.setBounds(this.boundsasany);}}publicshow(browserWindow: BrowserWindow,focus=true,waitForLoad=true){returnnewPromise((resolve)=>{this.browserWindow=browserWindow;clearTimeout(this.timeout);browserWindow.webContents.send('dialog-visibility-change',this.name,true,);constcallback=()=>{if(this.visible){if(focus)this.webContents.focus();return;}this.visible=true;browserWindow.addBrowserView(this.browserView);this.rearrange();if(focus)this.webContents.focus();resolve();};if(!this.loaded&&waitForLoad){this.showCallback=callback;return;}callback();});}publichideVisually(){this.send('visible',false);}publicsend(channel: string, ...args: any[]){this.webContents.send(channel, ...args);}publichide(bringToTop=false,hideVisually=true){if(!this.browserWindow)return;if(hideVisually)this.hideVisually();if(!this.visible)return;this.browserWindow.webContents.send('dialog-visibility-change',this.name,false,);if(bringToTop){this.bringToTop();}clearTimeout(this.timeout);if(this.hideTimeout){this.timeout=setTimeout(()=>{this.browserWindow.removeBrowserView(this.browserView);},this.hideTimeout);}else{this.browserWindow.removeBrowserView(this.browserView);}this.visible=false;// this.appWindow.fixDragging();}publicbringToTop(){this.browserWindow.removeBrowserView(this.browserView);this.browserWindow.addBrowserView(this.browserView);}publicdestroy(){this.browserView.destroy();this.browserView=null;}}
untill this issue is fixed i will leave this using BrowserView
Actual Behavior
n/A
Testcase Gist URL
No response
Additional Information
n?A
The text was updated successfully, but these errors were encountered:
Hello @IroniumStudios. Thanks for reporting this and helping to make Electron better!
Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.
Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.
Now adding the
blocked/need-reproNeeds a test case to reproduce the bug
label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.
The code you provided is your entire app with all included complexities and is therefore not suitable as a reproducible sample.
i could provide my projects source code with the changes that has th bug in it if that would help because the project is alittle complex for me to use the diolog code elsewhere
also, i suspect that the reasoning for my diologs not working correctly is that the WebContentsView dosent include all the diologs quit yet, am i correct?
Preflight Checklist
Electron Version
30.0.1
What operating system are you using?
Windows
Operating System Version
Windows 11 23H2
What arch are you using?
x64
Last Known Working Electron version
30.0.1
Expected Behavior
when i switch these lines of my diolog code below i get weird funkey rendering glitches like when i try and open cotext menus or hover over my objects i get weird gray boxes and then my app crashes when i try to make a new tab and i have tried properly initializing and that dident work ither
here are both of the diolog classes with the BrowserView even tho its depricated but i no longer have the WebContentsView version everty since iv had this issue
what im expecting is for all the diologs to show properly, with no gray boxes, and for the app to stop crashing when i try to do somethign e. g creating a new tab
diolog-service.ts
diolog.ts
untill this issue is fixed i will leave this using BrowserView
Actual Behavior
n/A
Testcase Gist URL
No response
Additional Information
n?A
The text was updated successfully, but these errors were encountered: