diff --git a/app/assets/javascripts/discourse/app/mixins/composer-video-thumbnail-uppy.js b/app/assets/javascripts/discourse/app/mixins/composer-video-thumbnail-uppy.js index 4e19080b77c..56f344543bc 100644 --- a/app/assets/javascripts/discourse/app/mixins/composer-video-thumbnail-uppy.js +++ b/app/assets/javascripts/discourse/app/mixins/composer-video-thumbnail-uppy.js @@ -162,5 +162,13 @@ export default class ComposerVideoThumbnailUppy extends EmberObject.extend( } }, 100); }; + + video.onerror = () => { + // eslint-disable-next-line no-console + console.warn( + "Video could not be loaded or decoded for thumbnail generation" + ); + callback(); + }; } } diff --git a/spec/system/composer_uploads_spec.rb b/spec/system/composer_uploads_spec.rb index 235a268c318..0a5b4e64f1a 100644 --- a/spec/system/composer_uploads_spec.rb +++ b/spec/system/composer_uploads_spec.rb @@ -117,6 +117,27 @@ describe "Uploading files in the composer", type: :system do end end + it "handles a video load error gracefully" do + visit "/new-topic" + expect(composer).to be_opened + topic.fill_in_composer_title("Video Load Error Test") + + # Inject JavaScript to simulate an invalid video file that triggers onerror + page.execute_script <<-JS + const originalCreateObjectURL = URL.createObjectURL; + URL.createObjectURL = function(blob) { + // Simulate an invalid video source by returning a fake object URL + return 'invalid_video_source.mp4'; + }; + JS + + file_path_1 = file_from_fixtures("small.mp4", "media").path + attach_file(file_path_1) { composer.click_toolbar_button("upload") } + + expect(composer).to have_no_in_progress_uploads + expect(composer.preview).to have_css(".onebox-placeholder-container") + end + it "shows video player in composer" do SiteSetting.enable_diffhtml_preview = true