-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix browser focus issue on MacOS #24892
Conversation
Thanks for taking the time to open a PR!
|
= seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
@@ -130,15 +131,15 @@ export = { | |||
return this.getBrowserInstance() | |||
}, | |||
|
|||
async open (browser: Browser, options: BrowserLaunchOpts, automation: Automation, ctx): Promise<BrowserInstance | null> { | |||
async open (browser: Browser, options: BrowserLaunchOpts, automation: Automation, ctx?: DataContext): Promise<BrowserInstance | null> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably NOT allowed to be nullable, but I'm not really sure, so I just made it nullable for now (previously it was any
, so at least this is more tightly typed).
// work around for a focus MacOS specific issue where the | ||
// browser is not correctly focused when launched. | ||
// https://github.com/cypress-io/cypress/issues/21743 | ||
ctx?.actions.browser.resetFocusIfMacOS() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the """fix""".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well for me., just one small nitpick Nice job tracking down something that works for this, and thanks for adding the additional typings throughout 💯
@@ -44,6 +44,14 @@ export class BrowserActions { | |||
await this.browserApi.focusActiveBrowserWindow() | |||
} | |||
|
|||
resetFocusIfMacOS () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/nit: Personal preference, I would put the "this is a workaround" and GH issue link on the function as JSDoc
I wasn't able to reproduce the issue on this branch 👍🏻 One thing that I'm seeing now though, is that once I launch Chrome from the launchpad, I can't find the launchpad window anymore... it is nowhere to be found. I see the Cy icon in my dock, but when I ask it to show me where the launchpad window is, it says that there aren't any windows. @mike-plummer are you also seeing this? https://www.loom.com/share/f411c08995134eeea27e6e1ba7ed0dec I think I see the same issue happen in the videos in the PR description. If you look closely you can see the launchpad window disappear once Chrome launches in the fixed video |
@astone123 Confirmed, I see this too. Didn't notice it in my earlier testing. If I update
|
@mike-plummer can confirm that this works, only thing is that the Launchpad window flashes over top of the browser for a split second after it launches... I wonder if that's something that we're willing to live with to fix this issue on MacOS? 🤔 |
Yeah I had considered this but I don't think it feels great... I didn't realize |
This is actually a bug in macos - I don't think we can "properly" fix it here, without the "flicker". I logged an issue in electron: electron/electron#36506 |
I am going to close this for now - we can revisit once we decide what we'd like to do, but none of the proposed solutions seems appropriate. |
User facing changelog
Fix a MacOS specific bug where the browser would not be correctly focused when launched.
Additional details
For reasons unknown, if you quickly jiggle your mouse back and forth when launching Chrome or Firefox browsers on MacOS, the browser would not be correctly focused. You can see this below in the first video - I jiggle my mouse, and then I need to click the search bar a bunch of times to get the browser to properly focus.
Note this also happens in Cypress 9 on the latest MacOS version. I reproduced it here: #21743 (comment)
There was a work around which was to switch to any other window, then switch back, and it would work as expected. I don't know why this fixes the issue, but i does. I was able to do the same thing programmatically, but simply showing and immediately hiding the electron app in code.
Bug
bug.mov
Fix
fix.mov
Steps to test
Note: You need to use MacOS to test this.
I see no practical way to write an automated test around this behavior. 🤔
How has the user experience changed?
The launched browser is now correctly focused.
PR Tasks
cypress-documentation
?type definitions
?