mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
- On graph change, set the `graph.id` as location hash - On hash change, navigate to the target `graph.id` either in the current, or any other loaded workflow. `canvasStore.currentGraph` does not trigger when `app.loadGraphData` is called. A trigger could be forced here, but I'm concerned about side effects. Instead `updateHash` is manually called. Code search shows that there are no current custom nodes using `onhashchange` ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6811-Allow-graph-navigation-by-browser-forward-backward-2b26d73d365081bb8414fdf7c3686124) by [Unito](https://www.unito.io) --------- Co-authored-by: Alexander Brown <drjkl@comfy.org>
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import { test as base } from '@playwright/test'
|
|
|
|
export const webSocketFixture = base.extend<{
|
|
ws: { trigger(data: unknown, url?: string): Promise<void> }
|
|
}>({
|
|
ws: [
|
|
async ({ page }, use) => {
|
|
// Each time a page loads, to catch navigations
|
|
page.on('load', async () => {
|
|
await page.evaluate(function () {
|
|
// Create a wrapper for WebSocket that stores them globally
|
|
// so we can look it up to trigger messages
|
|
const store: Record<string, WebSocket> = (window.__ws__ = {})
|
|
window.WebSocket = class extends window.WebSocket {
|
|
constructor(
|
|
...rest: ConstructorParameters<typeof window.WebSocket>
|
|
) {
|
|
super(...rest)
|
|
store[this.url] = this
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
await use({
|
|
async trigger(data, url) {
|
|
// Trigger a websocket event on the page
|
|
await page.evaluate(
|
|
function ([data, url]) {
|
|
if (!url) {
|
|
// If no URL specified, use page URL
|
|
const u = new URL(window.location.href)
|
|
u.hash = ''
|
|
u.protocol = 'ws:'
|
|
u.pathname = '/'
|
|
url = u.toString() + 'ws'
|
|
}
|
|
const ws: WebSocket = window.__ws__![url]
|
|
ws.dispatchEvent(
|
|
new MessageEvent('message', {
|
|
data
|
|
})
|
|
)
|
|
},
|
|
[JSON.stringify(data), url]
|
|
)
|
|
}
|
|
})
|
|
},
|
|
// We need this to run automatically as the first thing so it adds handlers as soon as the page loads
|
|
{ auto: true }
|
|
]
|
|
})
|