General developer forum

Local plugin javascript stops working randomly

Picture of Mark Sharp
Re: Local plugin javascript stops working randomly
Core developersParticularly helpful MoodlersPlugin developers

An event seems like an odd place to run javascript, they can and do run in background (e.g. user enrolment via cohort_sync in cron).

The reason you're getting the error is because in the context it's running requirejs hasn't been loaded - and that's probably related to it being in a context where it isn't usually loaded anyway.

By adding it to the navigation you could perhaps use javascript to in effect capture the course_viewed event, by using something like:

if($('body').hasClass('.path-course-view')) {
    // do something
Average of ratings: -