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;">
|
<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>
|
<h2 style="color: #d32f2f;">Authentication Error</h2>
|
||||||
<p>{error_message}</p>
|
<p>{error_message}</p>
|
||||||
<p>Please ensure you grant the requested permissions. You can close this window and try again.</p>
|
<p>Please ensure you grant the requested permissions. You can close this tab and try again.</p>
|
||||||
<script>setTimeout(function() {{ window.close(); }}, 10000);</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
@@ -176,9 +175,17 @@ def create_success_response(verified_user_id: Optional[str] = None) -> HTMLRespo
|
|||||||
}}
|
}}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
setTimeout(function() {{
|
function tryClose() {{
|
||||||
window.close();
|
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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -191,7 +198,7 @@ def create_success_response(verified_user_id: Optional[str] = None) -> HTMLRespo
|
|||||||
<div class="message">
|
<div class="message">
|
||||||
Your credentials have been securely saved. You can now close this window and retry your original command.
|
Your credentials have been securely saved. You can now close this window and retry your original command.
|
||||||
</div>
|
</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 class="auto-close">This window will close automatically in 10 seconds</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</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;">
|
<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>
|
<h2 style="color: #d32f2f;">Authentication Processing Error</h2>
|
||||||
<p>An unexpected error occurred while processing your authentication: {error_detail}</p>
|
<p>An unexpected error occurred while processing your authentication: {error_detail}</p>
|
||||||
<p>Please try again. You can close this window.</p>
|
<p>Please try again. You can close this tab.</p>
|
||||||
<script>setTimeout(function() {{ window.close(); }}, 10000);</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user