From 262991db6b1403c1fc977a56a153079596c69a4c Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Tue, 22 Apr 2025 16:18:25 -0400 Subject: [PATCH] [Bug] Prevent node pasting in signin dialog (#3568) --- browser_tests/fixtures/ComfyPage.ts | 2 +- browser_tests/tests/dialog.spec.ts | 27 +++++++++++++++++++++++++++ src/composables/usePaste.ts | 9 +++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/browser_tests/fixtures/ComfyPage.ts b/browser_tests/fixtures/ComfyPage.ts index b4ce59402f..caee56dcfa 100644 --- a/browser_tests/fixtures/ComfyPage.ts +++ b/browser_tests/fixtures/ComfyPage.ts @@ -926,7 +926,7 @@ export class ComfyPage { async getNodeRefById(id: NodeId) { return new NodeReference(id, this) } - async getNodes() { + async getNodes(): Promise { return await this.page.evaluate(() => { return window['app'].graph.nodes }) diff --git a/browser_tests/tests/dialog.spec.ts b/browser_tests/tests/dialog.spec.ts index 48267b1ac1..c7d2677675 100644 --- a/browser_tests/tests/dialog.spec.ts +++ b/browser_tests/tests/dialog.spec.ts @@ -341,3 +341,30 @@ test.describe('Error dialog', () => { await expect(errorDialog).toBeVisible() }) }) + +test.describe('Signin dialog', () => { + test('Paste content to signin dialog should not paste node on canvas', async ({ + comfyPage + }) => { + const nodeNum = (await comfyPage.getNodes()).length + await comfyPage.clickEmptyLatentNode() + await comfyPage.ctrlC() + + const textBox = comfyPage.widgetTextBox + await textBox.click() + await textBox.fill('test_password') + await textBox.press('Control+a') + await textBox.press('Control+c') + + await comfyPage.page.evaluate(() => { + window['app'].extensionManager.dialog.showSignInDialog() + }) + + const emailInput = comfyPage.page.locator('#comfy-org-sign-in-password') + await emailInput.waitFor({ state: 'visible' }) + await emailInput.press('Control+v') + await expect(emailInput).toHaveValue('test_password') + + expect(await comfyPage.getNodes()).toHaveLength(nodeNum) + }) +}) diff --git a/src/composables/usePaste.ts b/src/composables/usePaste.ts index 9a9eaa3761..ce6c68d823 100644 --- a/src/composables/usePaste.ts +++ b/src/composables/usePaste.ts @@ -38,6 +38,15 @@ export const usePaste = () => { } useEventListener(document, 'paste', async (e) => { + const isTargetInGraph = + e.target instanceof Element && + (e.target.classList.contains('litegraph') || + e.target.classList.contains('graph-canvas-container') || + e.target.id === 'graph-canvas') + + // If the target is not in the graph, we don't want to handle the paste event + if (!isTargetInGraph) return + // ctrl+shift+v is used to paste nodes with connections // this is handled by litegraph if (workspaceStore.shiftDown) return