Open susanBuck opened 1 month ago
Hi @susanBuck, thanks for reporting this! This is a warning rather than an error, and it's an annoying one because the jsPsych code isn't really doing anything wrong here. What's happening is that jsPsych always creates the Audio Context in case it's needed by plugins later on during the experiment. Most browsers require that the user makes some kind of interaction with the page (button cilck, key press) before the page can actually play audio, which makes sense. Unfortunately the browser is warning us that there hasn't been a user interaction at the point when we're creating the Audio Context, even though we're not actually trying to play anything!
My suggestion is to ignore this warning. If we do want to get rid of it, we could move the code that creates the Audio Context out of the constructor: https://github.com/jspsych/jsPsych/blob/9c6afb874251d6dd6d1c9917986869f239a972da/packages/jspsych/src/modules/plugin-api/MediaAPI.ts#L13-L21 And put it into any plugin API functions that require the Audio Context - these would check if it exists, and if not, create it.
Thoughts @jspsych/core?
@becky-gilbert - Thanks for the info! I'm teaching a class that uses jsPsych and the students were thrown off by the warning in the console. I've told them they can ignore it and showed how to filter out warnings from the console.
@susanBuck no problem! Yep, I can see why your students would be thrown off. Ideally jsPsych would not produce unnecessary console warnings since it can confuse new users, plus it makes it harder for all users to notice any other warnings.
I don't think this is a high-priority issue for the team right now, but I'll leave this issue open until we decide whether/when to fix it. In the meantime, it's safe to just ignore this.
Receiving the following warning in Google Chrome (129.0.6668.70) web inspector:
I understand the error occurs because browsers require interaction before allowing audio to play. However, I can recreate the issue in a barebones experiment with no audio-related plugins, just a simple html-keyboard-response.
JavaScript:
HTML: