-
Notifications
You must be signed in to change notification settings - Fork 405
fix: add closePopup option for Chrome extension compatibility #1500
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This fixes an issue where Chrome extensions would close prematurely when the popup window closes during authentication, interrupting the token exchange process. Changes: - Add closePopup option to PopupConfigOptions (default: true) - Modify utils.ts to conditionally close popup based on closePopup setting - Add finally block in Auth0Client.ts to close popup after token exchange - Always close popup on error cases (state mismatch, auth errors) Fixes #1318 Co-authored-by: ashwsn <[email protected]>
- Test default behavior (popup closes immediately) - Test explicit closePopup: true - Test closePopup: false (delays popup close until after token exchange) - Test error handling (state mismatch with closePopup: false) - Test finally block execution on token exchange failure
6 tasks
frederikprijck
requested changes
Jan 9, 2026
Member
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.
A boolean called closePopup to control when and not if a popup should be closed feels weird. I expect when setting it to false, it wouldnt close, so this code feels very unexpected:
if (config.closePopup === false && config.popup) {
config.popup.close();
}
- When closePopup: false, SDK no longer closes the popup - User is responsible for closing popup after loginWithPopup completes - Provides more flexibility and clearer API semantics - Updated tests and documentation to reflect new behavior This addresses feedback from @frederikprijck to avoid confusing behavior where closePopup: false still resulted in SDK closing the popup.
- Removed state mismatch error closing logic - When closePopup: false, user has full control over popup lifecycle including errors - Updated documentation to show try/finally pattern for proper cleanup - Updated comments to reflect new behavior - Removed state mismatch error test, updated remaining tests This simplifies the API - closePopup: false means SDK never touches the popup. User handles all cleanup in try/finally block.
frederikprijck
approved these changes
Jan 9, 2026
Merged
yogeshchoudhary147
added a commit
that referenced
this pull request
Jan 12, 2026
**Added** - fix: add closePopup option for Chrome extension compatibility [\#1500](#1500) ([yogeshchoudhary147](https://github.com/yogeshchoudhary147))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1318
Problem
When using
loginWithPopup()in Chrome extensions, the popup closes immediately after receiving the authorization response. This terminates the extension's service worker before token exchange completes, leaving the user unauthenticated.Solution
Added a
closePopupoption toPopupConfigOptions:true(default): SDK closes the popup automatically after receiving the authorization responsefalse: SDK does not close the popup. The caller is responsible for closing it, including on errors.This gives users full control over the popup lifecycle, which is especially useful for Chrome extensions where closing too early terminates the service worker.
Changes
closePopupoptionclosePopupoption with try/finally usage exampleclosePopupoptionUsage
This also provides flexibility for other use cases like showing post-login messages or executing additional logic before closing the popup.
Testing
Unit Tests
Added 4 test cases covering:
closePopup: trueclosePopup: false(SDK does not close popup on success)closePopup: false(SDK does not close popup on token exchange failure)All tests pass ✅
Manual Testing
Manually tested the fix in Chrome extension scenarios:
Before fix:
After fix with
closePopup: false:loginWithPopupcompletesOther scenarios:
Backward Compatibility
No breaking changes. Default behavior unchanged - popup still closes immediately after authorization.
Credits
This PR builds upon the initial investigation and work by @ashwsn.
Closes #1318