discourse/spec/lib/onebox
Martin Brennan 2b04fbeb30
FIX: Use oEmbed for YouTube oneboxing (#35959)
We currently rely on Open Graph data to render YouTube oneboxes.
However, YouTube does not always give us a response with the Open Graph
data necessary, leading to empty preview HTML like this that shows
as a broken image in the composer:

```
<img src="" width="480" height="360" title=" - YouTube" style="aspect-ratio: 480 / 360;">
```

In addition, our old method of parsing YouTube script tags for JSON
which contains information for the video, introduced in

4d669d2b71,
seems to no longer work reliably, possibly due to changes in YouTube's
JS structure.

To fix this, we switch to using YouTube's oEmbed endpoint which gives us
all the metadata we need for oneboxes in JSON format, including title,
author,
thumbnail URL, and video dimensions. This approach is more robust and
less likely to break
due to changes in YouTube's page structure.

c.f.
https://meta.discourse.org/t/youtube-uris-fail-to-render-thumbnails-when-oneboxed/387673
2025-11-12 14:13:16 +10:00
..
engine FIX: Use oEmbed for YouTube oneboxing (#35959) 2025-11-12 14:13:16 +10:00
domain_checker_spec.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
engine_spec.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
helpers_spec.rb DEV: Add a user agent to all HTTP requests that Discourse makes. (#31555) 2025-03-03 16:32:25 +11:00
json_ld_spec.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
layout_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
matcher_spec.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
movie_spec.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
oembed_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
open_graph_spec.rb FEATURE: Show more context in Discourse topic oneboxes 2023-01-11 14:22:53 +01:00
preview_spec.rb SECURITY: Fixes for main (#28137) 2024-07-30 14:19:01 +08:00
status_check_spec.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00