Skip to content

Add frontend pre and post debug message hooks#5495

Merged
knolleary merged 2 commits intomasterfrom
5489-frontend-hooks
Feb 25, 2026
Merged

Add frontend pre and post debug message hooks#5495
knolleary merged 2 commits intomasterfrom
5489-frontend-hooks

Conversation

@Steve-Mcl
Copy link
Copy Markdown
Contributor

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

closes #5489

Proposed changes

  • Updates editor-client/src/js/hooks.js
    • To support promise chaining (like the backend hooks in util/lib/hooks.js do)
    • Adds 2 known hooks debugPreProcessMessage and debugPostProcessMessage
    • Adds helper isKnownHook to permit node/plugin integrations to query if the hook they intend on attaching to is a known/supported hook
    • Various typedoc hints, linting and changing var to let/const
  • Updates nodes/core/common/lib/debug/debug-utils.js
    • handleDebugMessage
      • wrap call to processDebugMessage in the 2 new hooks debugPreProcessMessage and debugPostProcessMessage
    • processDebugMessage
      • allow extra tools to be passed to createObjectElement
      • always add red-ui-debug-msg-tools span element (function generated messages dont get a toolbar like all other messages)
      • return artifacts generated in the function - to permit debugPostProcessMessage hooks to affect the debug messages
        {
             message: o, // original debug message object, useful for any hook that might have tagged additional info onto it
             element: msg, // the top-level element for this debug message
             payload // the reconstructed debug message
         }

5.x stream

There is a 2nd PR here: #5490 - we can either merge that or wait until nr5 is merged into master

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@Steve-Mcl
Copy link
Copy Markdown
Contributor Author

Usage example - add extra button to warning & error level messages:

    if (RED.hooks.isKnownHook?.('debugPostProcessMessage')) {
        RED.hooks.add('debugPostProcessMessage.my-plugin', function (processedMessage) {
            const { message, element, payload } = processedMessage
            let tt = ''
            switch (message?.level) {
            case 20:
                tt = 'This is an error message. Click for details.'
                break
            case 30:
                tt = 'This is a warning message. Click for details.'
                break
            default:
                return // only interest in error and warning level messages
            }
            const metaRowTools = element.find('.red-ui-debug-msg-meta .red-ui-debug-msg-tools')
            if (metaRowTools.length) {
                const buttonEl = $('<button class="my-plugin-tool-button red-ui-button red-ui-button-small"><i class="fa fa-question"></i></button>')
                RED.popover.tooltip(buttonEl, tt)
                buttonEl.data('my-plugin-debug-data', { message, payload }) // for access to debug data in click handler
                buttonEl.on('click', function () {
                    const debugData = buttonEl.data('my-plugin-debug-data')
                    // Do the necessary with the debug data
                    if (debugData.message.level === 20) {
                        alert('Error messages are indicated by the red edges!\n\n' + JSON.stringify(debugData.message, null, 2))
                    } else if (debugData.message.level === 30) {
                        alert('Warning messages are indicated by the yellow edges!\n\n' + JSON.stringify(debugData.message, null, 2))
                    }
                })
                metaRowTools.append(buttonEl)
            }
        })
    } 

Example:

chrome_MCktEQjJ2R

@knolleary knolleary merged commit d4819dd into master Feb 25, 2026
5 checks passed
@knolleary knolleary deleted the 5489-frontend-hooks branch February 25, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Add frontend hooks for pre/post debug message

2 participants