diff --git a/custom-nodes/js/javascript_examples.mdx b/custom-nodes/js/javascript_examples.mdx index 3c3d5eeda..864d9eff9 100644 --- a/custom-nodes/js/javascript_examples.mdx +++ b/custom-nodes/js/javascript_examples.mdx @@ -119,6 +119,10 @@ import { api } from "../../scripts/api.js"; ## Detect an interrupted workflow + +**Deprecated:** The API hijacking pattern shown below is deprecated and subject to change at any point in the near future. Use the official [extension hooks](/custom-nodes/js/javascript_hooks) and API event listeners where available. + + A simple example of hijacking the api: ```Javascript @@ -134,6 +138,10 @@ import { api } from "../../scripts/api.js"; ## Catch clicks on your node + +**Deprecated:** The node method hijacking pattern shown below is deprecated and subject to change at any point in the near future. Use the official [extension hooks](/custom-nodes/js/javascript_hooks) where available. + + `node` has a mouseDown method you can hijack. This time we're careful to pass on any return value. diff --git a/custom-nodes/js/javascript_hooks.mdx b/custom-nodes/js/javascript_hooks.mdx index a4d4dfb49..41a7cdd45 100644 --- a/custom-nodes/js/javascript_hooks.mdx +++ b/custom-nodes/js/javascript_hooks.mdx @@ -50,6 +50,11 @@ might modify yours!), in which case care should be taken to ensure interoperabil And play nicely - isolate your changes wherever possible. A very common idiom in `beforeRegisterNodeDef` is to 'hijack' an existing method: + + +**Deprecated:** The prototype hijacking pattern shown below is deprecated and subject to change at any point in the near future. For context menus, use the official [Context Menu API](/custom-nodes/js/context-menu-migration) instead. For other use cases, prefer using the official [extension hooks](/custom-nodes/js/javascript_hooks) where available. + + ```Javascript async beforeRegisterNodeDef(nodeType, nodeData, app) { if (nodeType.comfyClass=="MyNodeClass") { @@ -70,6 +75,8 @@ or even make calling it conditional. When hijacking a method in this way, you will want to look at the core comfy code (breakpoints are your friend) to check and conform with the method signature. +This approach is fragile and may break with future ComfyUI updates. Use official APIs whenever possible. + #### nodeCreated() ```Javascript diff --git a/custom-nodes/js/javascript_objects_and_hijacking.mdx b/custom-nodes/js/javascript_objects_and_hijacking.mdx index 6a6571c2e..284b8fb65 100644 --- a/custom-nodes/js/javascript_objects_and_hijacking.mdx +++ b/custom-nodes/js/javascript_objects_and_hijacking.mdx @@ -14,6 +14,10 @@ which can be found at `doc/index.html`. The `app` object (always accessible by `import { app } from "../../scripts/app.js";`) represents the Comfy application running in the browser, and contains a number of useful properties and functions, some of which are listed below. + +**Deprecated:** Hijacking/monkey-patching functions on `app` or prototypes is deprecated and subject to change at any point in the near future. Use the official [extension hooks](/custom-nodes/js/javascript_hooks) and [Context Menu API](/custom-nodes/js/context-menu-migration) instead. + + Hijacking functions on `app` is not recommended, as Comfy is under constant development, and core behavior may change. ### Properties @@ -81,7 +85,11 @@ Group nodes, primitive nodes, notes, and redirect nodes have different propertie A `ComfyNode` object represents a node in the current workflow. It has a number of important properties that you may wish to make use of, a very large number of functions that you may wish to use, or hijack to -modify behavior. +modify behavior. + + +**Deprecated:** Hijacking prototype methods on `ComfyNode` or `LGraphNode` is deprecated and subject to change at any point in the near future. Use the official [extension hooks](/custom-nodes/js/javascript_hooks) where available, such as `getNodeMenuItems` for context menus. See the [Context Menu Migration Guide](/custom-nodes/js/context-menu-migration) for examples. + To get a more complete sense of the node object, you may find it helpful to insert the following code into your extension and place a breakpoint on the `console.log` command. When you then create a new node diff --git a/zh-CN/custom-nodes/js/javascript_examples.mdx b/zh-CN/custom-nodes/js/javascript_examples.mdx index 472b4becd..03646f639 100644 --- a/zh-CN/custom-nodes/js/javascript_examples.mdx +++ b/zh-CN/custom-nodes/js/javascript_examples.mdx @@ -116,6 +116,10 @@ import { api } from "../../scripts/api.js"; ## 检测工作流被中断 + +**已弃用:** 下面展示的 API 劫持模式已被弃用,可能在不久的将来随时更改。请尽可能使用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks) 和 API 事件监听器。 + + 这是一个劫持 api 的简单例子: ```Javascript @@ -131,6 +135,10 @@ import { api } from "../../scripts/api.js"; ## 捕获节点点击 + +**已弃用:** 下面展示的节点方法劫持模式已被弃用,可能在不久的将来随时更改。请尽可能使用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks)。 + + `node` 有一个 mouseDown 方法可以被劫持。 这次我们注意传递任何返回值。 diff --git a/zh-CN/custom-nodes/js/javascript_hooks.mdx b/zh-CN/custom-nodes/js/javascript_hooks.mdx index 286b014e5..761b08ae0 100644 --- a/zh-CN/custom-nodes/js/javascript_hooks.mdx +++ b/zh-CN/custom-nodes/js/javascript_hooks.mdx @@ -35,6 +35,11 @@ async beforeRegisterNodeDef(nodeType, nodeData, app) 由于其他扩展也可能会修改节点,建议尽量减少假设,并尽量隔离你的更改,友好共存。 在 `beforeRegisterNodeDef` 中非常常见的做法是"劫持"已有方法: + + +**已弃用:** 下面展示的原型劫持模式已被弃用,可能在不久的将来随时更改。对于右键菜单,请改用官方的 [右键菜单 API](/zh-CN/custom-nodes/js/context-menu-migration)。对于其他用例,请尽可能使用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks)。 + + ```Javascript async beforeRegisterNodeDef(nodeType, nodeData, app) { if (nodeType.comfyClass=="MyNodeClass") { @@ -51,6 +56,8 @@ async beforeRegisterNodeDef(nodeType, nodeData, app) { 以这种方式劫持方法时,建议查看核心 comfy 代码(断点调试很有用),以确保方法签名一致。 +这种方法比较脆弱,可能会在未来的 ComfyUI 更新中失效。请尽可能使用官方 API。 + #### nodeCreated() ```Javascript diff --git a/zh-CN/custom-nodes/js/javascript_objects_and_hijacking.mdx b/zh-CN/custom-nodes/js/javascript_objects_and_hijacking.mdx index abcf24ac1..bbedfc91a 100644 --- a/zh-CN/custom-nodes/js/javascript_objects_and_hijacking.mdx +++ b/zh-CN/custom-nodes/js/javascript_objects_and_hijacking.mdx @@ -11,6 +11,10 @@ Comfy 的许多功能都由 LiteGraph 提供,因此如果你要开发更复杂 `app` 对象(始终可通过 `import { app } from "../../scripts/app.js";` 获取)代表在浏览器中运行的 Comfy 应用,包含许多有用的属性和函数,部分如下所示。 + +**已弃用:** 劫持/猴子补丁 `app` 上的函数或原型方法已被弃用,可能在不久的将来随时更改。请改用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks) 和 [右键菜单 API](/zh-CN/custom-nodes/js/context-menu-migration)。 + + 不建议劫持 `app` 上的函数,因为 Comfy 正在持续开发,核心行为可能会变化。 ### 属性 @@ -74,6 +78,10 @@ ComfyNode_object_for_my_node.inputs.forEach(input => { `ComfyNode` 对象代表当前工作流中的一个节点。它有许多重要属性和大量可用或可劫持的函数,用于修改行为。 + +**已弃用:** 劫持 `ComfyNode` 或 `LGraphNode` 上的原型方法已被弃用,可能在不久的将来随时更改。请尽可能使用官方的 [扩展钩子](/zh-CN/custom-nodes/js/javascript_hooks),例如使用 `getNodeMenuItems` 处理右键菜单。参见 [右键菜单迁移指南](/zh-CN/custom-nodes/js/context-menu-migration) 获取示例。 + + 为了更全面地了解节点对象,你可以在扩展中插入如下代码,并在 `console.log` 处打断点。创建新节点时即可用调试器查看节点。 ```Javascript