[For Userscript Authors] WK Queue Manipulator

Hello there!

I’ve recently had an issue raised on my script, and after doing a little bit of digging, I think this could be related to this script.

In summary, the user reported that when using my script with the Back To Back script (which mainly just uses the queue manipulator to set some properties on the queue), they occasionally get this error:

This is kind of hard to debug, I haven’t been able to replicate it so far, but…

I can see that this isn’t directly an error in my script, and, so far, I have found the following in WaniKani’s code:

  1. The error is on this line: const stageNames = this.srsIdStageNames.get(srsId)
  2. this.srsIdStageNames is initialised in the constructor as this.srsIdStageNames = new Map(srsMap.srs_ids_stage_names), so something is going wrong there for it to return undefined.
  3. The srsMap comes from the quiz queue controller code, which initialises it as srsMap = JSON.parse(this.subjectIdsWithSRSTarget.innerText), so something must be wrong with the subjectIdsWithSrs.
  4. It could also be that the srsIdStageNames map does exist, but srsId can’t be found.

All I do in my script is: on a turbo:load event, replace the queue node with one that has updated SRS stage names in subjectIdsWithSRS. So, in my mind, the only thing that could even go wrong is the SRS stage names don’t get updated correctly. I wouldn’t have expected this crash, but I feel like I’m missing something. To be clear, my script does not use the queue manipulator.

The questions that I’m currently pondering on are:

  1. Is this an error you’ve encountered before?
  2. Am I missing something, or am doing something I’m not supposed to be doing in my script?
  3. Could anything in your script be causing this? Or, even just at which point this could be happening (i.e. how it can be replicated)?
  4. Is the Back To Back script doing something it’s not supposed to be doing with the queue manipulator?

Would you be able to help in answering any of these please? Any help would be really appreciated :folded_hands:

I’ll keep digging into this, and will report back if I find anything else.