diff --git a/src/ts/chat-parser.ts b/src/ts/chat-parser.ts index c0dc474a..60f3758d 100644 --- a/src/ts/chat-parser.ts +++ b/src/ts/chat-parser.ts @@ -89,7 +89,8 @@ const parseAddChatItemAction = (action: Ytc.AddChatItemAction, isReplay = false, const item: Ytc.ParsedMessage = { author: { - name: renderer.authorName.simpleText, + // It's apparently possible for there to be no author name (and only an author photo). + name: renderer.authorName?.simpleText ?? '', id: renderer.authorExternalChannelId, types: authorTypes, customBadge @@ -223,12 +224,17 @@ export const parseChatResponse = (response: string, isReplay: boolean): Ytc.Pars actionsArray.forEach((action) => { let parsedAction: Ytc.ParsedAction | undefined; - if (action.replayChatItemAction) { - const replayAction = action.replayChatItemAction; - const replayTimeMs = parseInt(replayAction.videoOffsetTimeMsec); - parsedAction = processCommonAction(replayAction.actions[0], isReplay, replayTimeMs); - } else { - parsedAction = processLiveAction(action, isReplay, liveTimeoutMs); + try { + if (action.replayChatItemAction) { + const replayAction = action.replayChatItemAction; + const replayTimeMs = parseInt(replayAction.videoOffsetTimeMsec); + parsedAction = processCommonAction(replayAction.actions[0], isReplay, replayTimeMs); + } else { + parsedAction = processLiveAction(action, isReplay, liveTimeoutMs); + } + } catch (error) { + console.error('Failed to parse action:', action); + throw error; } if (!parsedAction) { diff --git a/src/ts/typings/ytc.d.ts b/src/ts/typings/ytc.d.ts index 4e3efde2..73517570 100644 --- a/src/ts/typings/ytc.d.ts +++ b/src/ts/typings/ytc.d.ts @@ -133,7 +133,7 @@ declare namespace Ytc { interface TextMessageRenderer { message?: RunsObj; - authorName: SimpleTextObj; + authorName?: SimpleTextObj; authorBadges?: Array<{ liveChatAuthorBadgeRenderer: { /** Changes based on YT language */