diff --git a/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift b/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift index 4288ca8f3fe..d2cb14ea91e 100644 --- a/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift +++ b/apps/desktop/macos/autofill-extension/CredentialProviderViewController.swift @@ -139,13 +139,20 @@ class CredentialProviderViewController: ASCredentialProviderViewController { private func getWindowPosition() -> Position { let frame = self.view.window?.frame ?? .zero let screenHeight = NSScreen.main?.frame.height ?? 0 + let screenWidth = NSScreen.main?.frame.width ?? 0 // frame.width and frame.height is always 0. Estimating works OK for now. let estimatedWidth:CGFloat = 400; let estimatedHeight:CGFloat = 200; - let centerX = Int32(round(frame.origin.x + estimatedWidth/2)) - let centerY = Int32(round(screenHeight - (frame.origin.y + estimatedHeight/2))) - return Position(x: centerX, y:centerY) + // passkey modals are 600x600. + let modalHeight: CGFloat = 600; + let modalWidth: CGFloat = 600; + let centerX = round(frame.origin.x + estimatedWidth/2) + let centerY = round(screenHeight - (frame.origin.y + estimatedHeight/2)) + // Check if centerX or centerY are beyond either edge of the screen. If they are find the center of the screen, otherwise use the original value. + let positionX = centerX + modalWidth >= screenWidth || CGFloat(centerX) - modalWidth <= 0 ? Int32(screenWidth/2) : Int32(centerX) + let positionY = centerY + modalHeight >= screenHeight || CGFloat(centerY) - modalHeight <= 0 ? Int32(screenHeight/2) : Int32(centerY) + return Position(x: positionX, y: positionY) } override func loadView() {