fix: improve OAuth response pages for browser compatibility
window.close() is blocked by modern browsers for tabs not opened via window.open(). The success page's close button and auto-close timer silently fail as a result. - Add tryClose() that attempts window.close() and falls back to showing "You can close this tab manually" after 500ms - Remove ineffective auto-close scripts from error pages
This commit is contained in:
@@ -26,8 +26,7 @@ def create_error_response(error_message: str, status_code: int = 400) -> HTMLRes
|
||||
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 600px; margin: 40px auto; padding: 20px; text-align: center;">
|
||||
<h2 style="color: #d32f2f;">Authentication Error</h2>
|
||||
<p>{error_message}</p>
|
||||
<p>Please ensure you grant the requested permissions. You can close this window and try again.</p>
|
||||
<script>setTimeout(function() {{ window.close(); }}, 10000);</script>
|
||||
<p>Please ensure you grant the requested permissions. You can close this tab and try again.</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
@@ -176,9 +175,17 @@ def create_success_response(verified_user_id: Optional[str] = None) -> HTMLRespo
|
||||
}}
|
||||
</style>
|
||||
<script>
|
||||
setTimeout(function() {{
|
||||
function tryClose() {{
|
||||
window.close();
|
||||
}}, 10000);
|
||||
// If window.close() was blocked by the browser, update the UI
|
||||
setTimeout(function() {{
|
||||
var btn = document.querySelector('.button');
|
||||
if (btn) btn.textContent = 'You can close this tab manually';
|
||||
var ac = document.querySelector('.auto-close');
|
||||
if (ac) ac.style.display = 'none';
|
||||
}}, 500);
|
||||
}}
|
||||
setTimeout(tryClose, 10000);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
@@ -191,7 +198,7 @@ def create_success_response(verified_user_id: Optional[str] = None) -> HTMLRespo
|
||||
<div class="message">
|
||||
Your credentials have been securely saved. You can now close this window and retry your original command.
|
||||
</div>
|
||||
<button class="button" onclick="window.close()">Close Window</button>
|
||||
<button class="button" onclick="tryClose()">Close Window</button>
|
||||
<div class="auto-close">This window will close automatically in 10 seconds</div>
|
||||
</div>
|
||||
</body>
|
||||
@@ -215,8 +222,7 @@ def create_server_error_response(error_detail: str) -> HTMLResponse:
|
||||
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 600px; margin: 40px auto; padding: 20px; text-align: center;">
|
||||
<h2 style="color: #d32f2f;">Authentication Processing Error</h2>
|
||||
<p>An unexpected error occurred while processing your authentication: {error_detail}</p>
|
||||
<p>Please try again. You can close this window.</p>
|
||||
<script>setTimeout(function() {{ window.close(); }}, 10000);</script>
|
||||
<p>Please try again. You can close this tab.</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user