Fix: Resolve BrowserView attachment error on password unlock
Fixes JavaScript error "given browserview is not attached to the window" that occurred when unlocking the screen after boot with password protection. Changes to unlockScreen() function: - Add try-catch around hidden view restoration to prevent crashes - Ensure view is attached with addBrowserView() before setTopBrowserView() - Add fallback to regular views if hidden view restoration fails - Validate currentIndex is within bounds before using it - Check views.length>0 before attempting to attach views This ensures safe view restoration in all unlock scenarios, particularly when unlocking immediately after boot with password protection enabled.
This commit is contained in:
@@ -4040,12 +4040,26 @@ function unlockScreen(){
|
||||
}
|
||||
|
||||
// Restore current view using proper method
|
||||
// For boot unlock, always use attachView for regular views (safe path)
|
||||
if(showingHidden&&hiddenViews[currentHiddenIndex]){
|
||||
const[w,h]=mainWindow.getContentSize();
|
||||
mainWindow.setTopBrowserView(hiddenViews[currentHiddenIndex]);
|
||||
hiddenViews[currentHiddenIndex].setBounds({x:0,y:0,width:w,height:h});
|
||||
}else if(views[currentIndex]){
|
||||
attachView(currentIndex);
|
||||
try{
|
||||
const[w,h]=mainWindow.getContentSize();
|
||||
// Ensure view is added to window before setting as top
|
||||
mainWindow.addBrowserView(hiddenViews[currentHiddenIndex]);
|
||||
mainWindow.setTopBrowserView(hiddenViews[currentHiddenIndex]);
|
||||
hiddenViews[currentHiddenIndex].setBounds({x:0,y:0,width:w,height:h});
|
||||
}catch(e){
|
||||
console.error('[LOCKOUT] Error restoring hidden view:',e);
|
||||
// Fallback to regular views
|
||||
if(views.length>0){
|
||||
showingHidden=false;
|
||||
attachView(0);
|
||||
}
|
||||
}
|
||||
}else if(views.length>0){
|
||||
// Use valid index or default to 0
|
||||
const idx=(currentIndex>=0&¤tIndex<views.length)?currentIndex:0;
|
||||
attachView(idx);
|
||||
}
|
||||
|
||||
// Start master timer if not already running (handles boot password case)
|
||||
|
||||
Reference in New Issue
Block a user