This is not a problem but a “how-to” (and a gentle nudge to update the jsPsych documentation page). After finding a couple of posts wondering how to do this that never got a clear answer (e.g., jsPsych Pavlovia plugin - Problems with redirecting participants after completion), I worked out what seems to be a fairly reliable solution and wanted to share it.
This is based on jsPsych 7.1.2 and the 2022.1.1 version of the Pavlovia plugin for jsPsych, but should work in any version with the Pavlovia plugin.
In short, you can add an “on_finish” trigger to the Pavlovia “finish” timeline element, like so:
var pavlovia_finish = {
type: jsPsychPavlovia,
command: "finish",
on_finish: function (){
document.body.innerHTML = '<p> Please wait. You will be redirected back to Prolific in a few moments. If you get a pop-up warning you "data may not be saved", you can click "leave", your data have already been saved.</p>';
setTimeout(function () {
location.href = "https://app.prolific.co/submissions/complete?cc=XXXXXX";
document.body.innerHTML ='<p>If you are not automatically redirected, please click here: <a href="https://app.prolific.co/submissions/complete?cc=XXXXXX">https://app.prolific.co/submissions/complete?cc=XXXXXX</a></p><p>If you get a pop-up warning you "data may not be saved", you can click "leave", your data have already been saved.</p>';
}, 5000);
}
};
I added a 5-second delay just to be safe, but in principle “on_finish” only triggers after the pavlova server acknowledges the data upload, so you may be able to just redirect immediately. I have tested this code and can confirm the data are saved successfully on the server before the redirect occurs.
However, you may notice the extra comment about a pop-up stating “are you sure you want to leave? Your data may not be saved”. This is because, at least on Chrome on my computer, for whatever reason this gets treated like an incomplete form and warns you that you are leaving without completing it.
I haven’t figured out a good way around that, because it doesn’t seem to recognize the on_finish trigger at the experiment level when you use the Pavlovia plugin, but it does recognize it at the trial level. I’m not entirely sure why, but it seems like something in the plugin stops jsPsych from recognizing the timeline completion.