Javascript code on remote page not executed in external-html plugin
See original GitHub issueFirst, thanks for making jspsych. It is a great help for our projects here at Mozilla.
I noticed an issue with the external-html plugin as it does not execute <script> tags that are included in the remote html page. The problem is that scripts injected by innerHTML on line 85 are inactive.
One solution for this could be to relocate each <script>
tag through DOM manipulation to activate their content. I suggest to control this via an additional executeScript parameter.
Parameter definition:
// this code snippet needs to become a new parameter in plugin.info
executeScript: {
type: jsPsych.plugins.parameterType.BOOL,
pretty_name: 'Execute scripts',
default: false,
description: 'If true, executes scripts on the external html file.'
Then, on line 69 add the following code:
// Scripts injected by innerHTML are inactive.
// To activate them, relocate them through DOM manipulation.
// Only run this if the executeScript parameter is set to true
if (trial.executeScript) {
for (const scriptElement of display_element.getElementsByTagName("script")) {
const relocatedScript = document.createElement("script");
relocatedScript.text = scriptElement.text;
scriptElement.parentNode.replaceChild(relocatedScript, scriptElement);
}
}
Happy to turn this into a PR if you wish.
Thanks again, Dominik
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Chrome extension adding external javascript to current page's ...
I am adding some external JavaScript to the end of the page via my chrome extension. The external JavaScript then tries to post...
Read more >How to Load External JavaScript Files From the Browser ...
This article will explain how you can load an external JavaScript file ... Note the use of eval() to execute the code is...
Read more >Safely inserting external content into a page - Mozilla | MDN
This situation can leave a user's browser open to remote attack by enabling the website that injected the code to access critical user...
Read more >Call JavaScript function from HTML: Different methods - Flexiple
Let us now look at the different methods to call JavaScript functions from HTML pages. Using the script tags. This is one of...
Read more >external-html plugin - jsPsych
The HTML plugin displays an external HTML document (often a consent form). ... boolean, false, If true , then scripts on the remote...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree that this will most likely also solve #332. In the pull request, I made the parameter to run scripts
false
by default.I think that also documentation update is required.
@onkeltom Aha, awesome catch! Thank you so much! Really does help to have another set of eyes. Many thanks once again!