fix(editor): Return early in ws message handler if no 'command' keyword is found (#7946)

## Summary
Avoid processing websocket messages not n8n sent (filter on 'command'
keyword)
This commit is contained in:
Csaba Tuncsik
2023-12-08 13:42:50 +01:00
committed by GitHub
parent dcf12867b3
commit 5b2defc867
3 changed files with 81 additions and 65 deletions

View File

@@ -136,21 +136,22 @@ const onMouseLeave = () => {
};
const receiveMessage = ({ data }: MessageEvent) => {
if (data?.includes('"command"')) {
try {
const json = JSON.parse(data);
if (json.command === 'n8nReady') {
ready.value = true;
} else if (json.command === 'openNDV') {
nodeViewDetailsOpened.value = true;
} else if (json.command === 'closeNDV') {
nodeViewDetailsOpened.value = false;
} else if (json.command === 'error') {
emit('close');
}
} catch (e) {
console.error(e);
if (!data?.includes?.('"command"')) {
return;
}
try {
const json = JSON.parse(data);
if (json.command === 'n8nReady') {
ready.value = true;
} else if (json.command === 'openNDV') {
nodeViewDetailsOpened.value = true;
} else if (json.command === 'closeNDV') {
nodeViewDetailsOpened.value = false;
} else if (json.command === 'error') {
emit('close');
}
} catch (e) {
console.error(e);
}
};
const onDocumentScroll = () => {