Added try/catch to iFrame buffering in Settings (#19790)

refs https://ghost.slack.com/archives/CTH5NDJMS/p1709230854358779

- Customer reported that some code they injected via the Code Injection
crashed the Preview in Ghost Settings.
- This wraps the function where the crash took place (according to
Sentry) in a try/catch to attempt to handle it gracefully.
- Added an additional Sentry log to better understand the situation
should it happen again.
This commit is contained in:
Ronald Langeveld 2024-03-04 11:11:03 +02:00 committed by GitHub
parent 9df5148427
commit 2816c2c128
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,4 @@
import * as Sentry from '@sentry/react';
import React, {useEffect, useRef, useState} from 'react';
type IframeBufferingProps = {
@ -62,7 +63,15 @@ const IframeBuffering: React.FC<IframeBufferingProps> = ({generateContent, class
const iframe = iframes[visibleIframeIndex].current;
if (iframe) {
iframe.contentWindow?.scrollTo(0, scrollPosition);
// refs https://ghost-foundation.sentry.io/issues/5024564293/
// Customer reported that code they injected caused Settings to crash.
// According to Sentry this the line that caused the crash.
// We are adding a try catch block to attempt to catch the error for further investigation and prevent the crash.
try {
iframe.contentWindow?.scrollTo(0, scrollPosition);
} catch (e) {
Sentry.captureException(e);
}
}
}, [scrollPosition, visibleIframeIndex, iframes]);