question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Javascript code on remote page not executed in external-html plugin

See original GitHub issue

First, 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:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
onkeltomcommented, May 31, 2018

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.

0reactions
coyiutoccommented, Jun 4, 2018

@onkeltom Aha, awesome catch! Thank you so much! Really does help to have another set of eyes. Many thanks once again!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found