Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/host/attach.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions src/main/lib/comfyAuthPopupErrorContentScript.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/// <reference lib="dom" />
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<void> {
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)
})
})
44 changes: 44 additions & 0 deletions src/main/lib/comfyAuthPopupErrorContentScript.ts
Original file line number Diff line number Diff line change
@@ -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<muts.length;i++){` +
`var added=muts[i].addedNodes;` +
`for(var j=0;j<added.length;j++){` +
`var n=added[j];` +
`if(looksBlocked(n)){nukeToast(n);continue;}` +
`if(n.querySelectorAll){` +
`var hits=n.querySelectorAll('*');` +
`for(var k=0;k<hits.length;k++){` +
`if(looksBlocked(hits[k])){nukeToast(hits[k]);break;}` +
`}` +
`}` +
`}` +
`}` +
`});` +
`window.__comfyDesktopAuthPopupErrorSuppressor=observer;` +
`observer.observe(document.documentElement,{childList:true,subtree:true});` +
`})()`
)
}
Loading