From 569244919db3f0d5d8fb17b9cda5313564942472 Mon Sep 17 00:00:00 2001 From: Wayne Sutton Date: Sat, 20 Dec 2025 23:29:32 -0800 Subject: [PATCH] fix: move window.open before await to avoid popup blocker When content exceeds URL length limit, the async clipboard write was blocking the window.open call. Browsers require window.open to happen synchronously within user gesture handlers. --- src/components/CopyPageDropdown.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/CopyPageDropdown.tsx b/src/components/CopyPageDropdown.tsx index 3304591..31d73da 100644 --- a/src/components/CopyPageDropdown.tsx +++ b/src/components/CopyPageDropdown.tsx @@ -291,18 +291,19 @@ export default function CopyPageDropdown(props: CopyPageDropdownProps) { // Generic handler for opening AI services // All services receive the full markdown content directly + // IMPORTANT: window.open must happen BEFORE any await to avoid popup blockers const handleOpenInAI = async (service: AIService) => { const markdown = formatAsMarkdown(props); const prompt = `Please analyze this article:\n\n${markdown}`; // Build the target URL using the service's buildUrl function if (!service.buildUrl) { - // Fallback: copy to clipboard and open base URL + // Fallback: open base URL FIRST (sync), then copy to clipboard + window.open(service.baseUrl, "_blank"); const success = await writeToClipboard(markdown); if (success) { setFeedback("url-too-long"); setFeedbackMessage("Copied! Paste in " + service.name); - window.open(service.baseUrl, "_blank"); } else { setFeedback("error"); setFeedbackMessage("Failed to copy content"); @@ -313,13 +314,14 @@ export default function CopyPageDropdown(props: CopyPageDropdownProps) { const targetUrl = service.buildUrl(prompt); - // Check URL length - if too long, copy to clipboard instead + // Check URL length - if too long, open base URL then copy to clipboard if (isUrlTooLong(targetUrl)) { + // Open window FIRST (must be sync to avoid popup blocker) + window.open(service.baseUrl, "_blank"); const success = await writeToClipboard(markdown); if (success) { setFeedback("url-too-long"); setFeedbackMessage("Copied! Paste in " + service.name); - window.open(service.baseUrl, "_blank"); } else { setFeedback("error"); setFeedbackMessage("Failed to copy content");