Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] h5p.js:997 Uncaught ReferenceError: H5PIntegration is not defined #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thibsy
Copy link

@thibsy thibsy commented Jan 25, 2023

Hi all,

Since, unfortunately, there is absolutely no documentation about how to develop an H5P editor for a platform integration, I assume to have stumbled upon a bug. If I'm wrong, you guys can gladly point me in the right direction and close this PR.

The problem in question: It is my understanding that you should not initialize the H5P kernel with H5P.init() on clientside, if there are no H5P contents. Therefore, if I had merely an H5P Editor on the page, I would assume to only call H5PEditor.init() to create a new instance of such editor.

This lead to an issue for me because the iFrame apparently could not locate the H5PIntegration object anymore, which is globally available in its parent window though. Then I realized when initializing H5P contents which are embeded in an iFrame, the H5P.init() function adds a neat little snippet to the iFrame's <head> which also solved the problem in the editor for me:

H5PIntegration = window.parent.H5PIntegration; var H5P = H5P || {}; H5P.externalEmbed = false;

This PR introduces the same snippet for the iFrame's <head> element when creating a new Editor instance, so the H5PIntegration object can be found as well. Otherwise, calling H5PEditor.init() lead to the following two issues:

h5p.js:997 Uncaught ReferenceError: H5PIntegration is not defined
    at H5P.t (h5p.js:997:3)
    at HTMLDocument.<anonymous> (h5p.js:2717:18)
    at c (jquery.js:2:7857)
    at Object.fireWith [as resolveWith] (jquery.js:2:8658)
    at Function.ready (jquery.js:2:3266)
    at HTMLDocument.H (jquery.js:2:695)

h5peditor-init.js:108 Uncaught ReferenceError: H5PIntegration is not defined
    at H5PEditor.getAjaxUrl (h5peditor-init.js:108:15)
    at HTMLIFrameElement.load (h5peditor-editor.js?version=7.17_2022-12-21:194:41)
    at HTMLIFrameElement.dispatch (jquery.js?version=7.17_2022-12-21:2:28337)
    at v.handle (jquery.js?version=7.17_2022-12-21:2:25042)

Kind regards,
@thibsy

@thibsy
Copy link
Author

thibsy commented Jan 25, 2023

If anyone is wondering how to work around this issue, I came up with the following little hack:

let editor_wrapper = document.getElementById(editor_id);
// grab other elements for the init function.
// ...

H5PEditor.init(
    $(editor_form),
    $(editor_action),
    $(editor_upload),
    $(editor_wrapper),
    $(editor_element),
    $(editor_library),
    $(editor_params)
);

// add event listener which fixes the H5PIntegration bug.
editor_wrapper.querySelector('.h5p-editor-iframe')
    ?.addEventListener('load', function () {
        this.H5PIntegration = parent.H5PIntegration;
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant