diff --git a/src/main/host/attach.ts b/src/main/host/attach.ts index 797df550e..d81069cee 100644 --- a/src/main/host/attach.ts +++ b/src/main/host/attach.ts @@ -1,6 +1,7 @@ import * as ipc from '../lib/ipc' import { getAppVersion } from '../lib/ipc' import { attachSessionDownloadHandler } from '../lib/comfyDownloadManager' +import { getComfyAuthPopupErrorContentScript } from '../lib/comfyAuthPopupErrorContentScript' import { getModelDownloadContentScript } from '../lib/comfyContentScript' import { getComfyTerminalContentScript } from '../lib/comfyTerminalContentScript' import { closeInstallPopouts } from '../lib/popoutWindows' @@ -406,6 +407,13 @@ export function attachInstall(entry: ComfyWindowEntry, opts: AttachInstallOpts): const onDomReady = (): void => { comfyContents.executeJavaScript(COMFY_THEME_OBSERVER_JS).catch(() => {}) comfyContents.executeJavaScript(getModelDownloadContentScript()).catch(() => {}) + // Local views were missing the false popup-error suppression already + // included in the Cloud patches below. + if (isLocal) { + comfyContents + .executeJavaScript(getComfyAuthPopupErrorContentScript()) + .catch(() => {}) + } // Inject the Terminal bottom-panel tab on local managed installs that // back it with a per-install shell (standalone, portable, git). They all // ship the same served frontend and expose the same diff --git a/src/main/lib/comfyAuthPopupErrorContentScript.test.ts b/src/main/lib/comfyAuthPopupErrorContentScript.test.ts new file mode 100644 index 000000000..49178664a --- /dev/null +++ b/src/main/lib/comfyAuthPopupErrorContentScript.test.ts @@ -0,0 +1,63 @@ +/// +import { afterEach, describe, expect, it } from 'vitest' +import { getComfyAuthPopupErrorContentScript } from './comfyAuthPopupErrorContentScript' + +type SuppressorWindow = Window & { + __comfyDesktopAuthPopupErrorSuppressor?: MutationObserver +} + +describe('getComfyAuthPopupErrorContentScript', () => { + const script = getComfyAuthPopupErrorContentScript() + const suppressorWindow = window as SuppressorWindow + + afterEach(() => { + suppressorWindow.__comfyDesktopAuthPopupErrorSuppressor?.disconnect() + delete suppressorWindow.__comfyDesktopAuthPopupErrorSuppressor + document.body.innerHTML = '' + }) + + function installSuppressor(): void { + new Function(script)() + } + + function flushObserver(): Promise { + return new Promise((resolve) => setTimeout(resolve, 0)) + } + + it('returns a syntactically valid, self-contained IIFE', () => { + expect(script.startsWith('(function(){')).toBe(true) + expect(() => new Function(script)).not.toThrow() + }) + + it('removes popup-blocked and mapped sign-in errors but preserves unrelated toasts', async () => { + installSuppressor() + + const rawError = document.createElement('div') + rawError.setAttribute('role', 'alert') + rawError.textContent = 'Firebase: Error (auth/popup-blocked).' + + const mappedError = document.createElement('div') + mappedError.className = 'p-toast-message' + mappedError.textContent = 'Something went wrong while signing you in. Please try again.' + + const unrelatedError = document.createElement('div') + unrelatedError.setAttribute('role', 'alert') + unrelatedError.textContent = 'Failed to download the selected model.' + + document.body.append(rawError, mappedError, unrelatedError) + await flushObserver() + + expect(rawError.isConnected).toBe(false) + expect(mappedError.isConnected).toBe(false) + expect(unrelatedError.isConnected).toBe(true) + }) + + it('does not install duplicate observers on the same page', () => { + installSuppressor() + const firstObserver = suppressorWindow.__comfyDesktopAuthPopupErrorSuppressor + + installSuppressor() + + expect(suppressorWindow.__comfyDesktopAuthPopupErrorSuppressor).toBe(firstObserver) + }) +}) diff --git a/src/main/lib/comfyAuthPopupErrorContentScript.ts b/src/main/lib/comfyAuthPopupErrorContentScript.ts new file mode 100644 index 000000000..6d18c3472 --- /dev/null +++ b/src/main/lib/comfyAuthPopupErrorContentScript.ts @@ -0,0 +1,44 @@ +/** + * Returns a self-contained script that removes the false Firebase popup error + * produced when Desktop denies the embedded auth popup and takes over with its + * system-browser sign-in flow. + * + * Cloud views already include this suppression in their existing patch bundle. + * Local ComfyUI uses the same popup interception, so this script adds only the + * missing local behavior. It matches the raw popup-blocked error or the + * frontend's dedicated user-facing sign-in failure copy. + */ +export function getComfyAuthPopupErrorContentScript(): string { + return ( + `(function(){` + + `if(window.__comfyDesktopAuthPopupErrorSuppressor)return;` + + `function looksBlocked(n){` + + `if(!n||n.nodeType!==1)return false;` + + `var t=(n.textContent||'').toLowerCase();` + + `return t.indexOf('auth/popup-blocked')>=0` + + `||t.indexOf('signing you in')>=0;` + + `}` + + `function nukeToast(n){` + + `var root=(n.closest&&n.closest('.p-toast-message,.p-toast-item,[role=alert]'))||n;` + + `try{root.remove()}catch(_){}` + + `}` + + `var observer=new MutationObserver(function(muts){` + + `for(var i=0;i