Use div embed regardless of H5P plugin

Created on 21 August 2025, about 2 months ago

Problem/Motivation

See 🐛 D11 Console Errors Active and the linked issues.

The logic in the H5P formatter to embed activities and all of their js and css dependencies via iframe is very, very fragile. It was not compatible with Drupal 11 and unfortunately making it compatible with Drupal 11 still has some unresolved bugs.

However, when embedding content via div, we're able to rely on Drupal's asset system much more closely, completely avoiding the problematic code.

Steps to reproduce

Proposed resolution

Always embed H5P content via div.

See also https://h5p.org/node/99838

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @catch
  • 🇬🇷Greece vensires

    Taking into account the libraries depicted in https://h5p.org/node/99838, it seems that most don't support <div> but <iframe>:

    While developing custom H5P libraries for a project of ours, I also used iFrame for two reasons:
    a) I wanted my solution to coexist with other H5P content in a Quiz content type I had built
    b) I liked the fact that my JS/CSS code wouldn't interfere with other code of the main page
    More or less, the same reasons also described in that h5p.org node you mentioned in the issue summary.

    If we are to hardcode the change from the iframe to div, I think a major release should exist. I personally find it better though to instead add a setting in the formatter in order to let the user decide whether iframe or div will be used.

  • 🇬🇧United Kingdom catch

    We've been using div embeds for H5P types that supposedly only support iframe, while I can see the reasons, there are other ways to handle js/css interference.

    The big problem with the iframe embeds is the interaction between the Drupal asset system and the H5P API - the H5P assets are being put into the asset API, then taken out again. If there was a way to make it more genuinely standalone that might be OK too, but it would be a significant change to the module.

  • 🇺🇸United States frob US

    I am a little lost as to what it entails to do this? Wouldn't forcing <div> embedding also have the side effect of removing the ability to remote embed?

    This sounds like a pretty major undertaking.

    I don't get this statement.

    The logic in the H5P formatter to embed activities and all of their js and css dependencies via iframe is very, very fragile. It was not compatible with Drupal 11 and unfortunately making it compatible with Drupal 11 still has some unresolved bugs.

    In my experience, iframe embedding is much more robust than div embedding because iframes isolate their content in a separate context. This isolation prevents conflicts between the embedded content's assets (CSS, JavaScript, etc.) and the parent HTML document's assets, making the embedding more stable and reliable.

  • 🇬🇧United Kingdom catch

    @frob take a look at the H5P field formatter and the difference between the div and iframe embed logic in there.

  • 🇫🇮Finland anaconda777

    Just a side note and a question. I use only iframes to show H5P content because I can have ten H5P content simultaneously at the same page.
    To make the page faster, I load the H5P iframe only when user clicks the div element, and the H5P is then loaded. This just makes
    the page ligher and faster to load. I am not sure could this be done with DIVs? Could I have "empty" divs and load the H5P there when user clicks a link? If thats possible I would maybe use divs to be able to use site wide CSS.

  • 🇬🇧United Kingdom catch

    @anaconda777 are you doing that with the H5P field formatter? This change would only affect that and nothing else.

Production build 0.71.5 2024