From 4bcd3efa11910bcadbcf529af6faac16458026e1 Mon Sep 17 00:00:00 2001 From: Elijah Kuntz Date: Thu, 11 Jun 2026 11:36:27 -0700 Subject: [PATCH] Popup when detected adblock breaking onlyoffice --- frontend/src/components/OnlyOfficeEditor.tsx | 78 ++++++++++++++++++-- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/OnlyOfficeEditor.tsx b/frontend/src/components/OnlyOfficeEditor.tsx index 6300cbc..7d3335b 100644 --- a/frontend/src/components/OnlyOfficeEditor.tsx +++ b/frontend/src/components/OnlyOfficeEditor.tsx @@ -1,6 +1,6 @@ -import React, { useEffect, useState, useRef } from 'react'; +import React, { useEffect, useState, useRef, useCallback } from 'react'; import { DocumentEditor } from '@onlyoffice/document-editor-react'; -import { Sun, Moon, Loader2, ArrowLeft, RefreshCw, Download } from 'lucide-react'; +import { Sun, Moon, Loader2, ArrowLeft, RefreshCw, Download, ShieldAlert, X } from 'lucide-react'; import api from '@/lib/api'; import { FileItem } from '@/types/files'; @@ -18,6 +18,10 @@ export default function OnlyOfficeEditor({ file, type, onClose, onRename, theme, const [loadError, setLoadError] = useState(null); const [config, setConfig] = useState(null); const [isRenaming, setIsRenaming] = useState(false); + const [adblockWarning, setAdblockWarning] = useState(false); + const [documentReady, setDocumentReady] = useState(false); + const documentReadyRef = useRef(false); + const loadTimeoutRef = useRef(null); const extMatch = file.name.match(/\.[^.]+$/); const ext = extMatch ? extMatch[0] : ''; @@ -130,9 +134,39 @@ export default function OnlyOfficeEditor({ file, type, onClose, onRename, theme, const docServerUrl = process.env.NEXT_PUBLIC_ONLYOFFICE_URL || 'https://office.elijahkuntz.com/'; - const onDocumentReady = function (event: any) { + // Proactively detect if an adblocker is blocking OnlyOffice resources + useEffect(() => { + if (!config) return; + + // Test fetch for a resource commonly blocked by adblockers (Brave Shields, uBlock, etc.) + const testUrl = `${docServerUrl}web-apps/apps/common/Analytics.js`; + fetch(testUrl, { method: 'HEAD', mode: 'no-cors' }) + .then(() => { + // mode: 'no-cors' always resolves — check with a timeout fallback instead + }) + .catch(() => { + setAdblockWarning(true); + }); + + // Fallback: if onDocumentReady hasn't fired in 8s, show the warning + loadTimeoutRef.current = setTimeout(() => { + if (!documentReadyRef.current) { + setAdblockWarning(true); + } + }, 8000); + + return () => { + if (loadTimeoutRef.current) clearTimeout(loadTimeoutRef.current); + }; + }, [config, docServerUrl]); + + const onDocumentReady = useCallback(function (event: any) { console.log("Document is loaded"); - }; + documentReadyRef.current = true; + setDocumentReady(true); + setAdblockWarning(false); + if (loadTimeoutRef.current) clearTimeout(loadTimeoutRef.current); + }, []); const onLoadComponentError = function (errorCode: number, errorDescription: string) { setLoadError(`${errorCode}: ${errorDescription}`); @@ -192,16 +226,44 @@ export default function OnlyOfficeEditor({ file, type, onClose, onRename, theme,
{loadError ? ( -
+
-

Failed to load OnlyOffice Editor

-

{loadError}

-

Check if your OnlyOffice server is running and accessible at the configured URL.

+

Failed to load OnlyOffice Editor

+

{loadError}

+

Check if your OnlyOffice server is running and accessible at the configured URL.

) : (
+ {/* Adblocker / Brave Shields warning banner */} + {adblockWarning && !documentReady && ( +
+ +
+

Ad Blocker Detected

+

+ Your ad blocker or browser shield is blocking resources required by the document editor. + The editor may not load or function correctly. +

+
+

To fix this:

+
    +
  • Brave: Click the Shields icon (lion) in the address bar → set Shields to Down for this site
  • +
  • uBlock / AdBlock: Click the extension icon → disable for this site
  • +
+

Then refresh the page.

+
+
+ +
+ )}