Scripts under discourse api events are failed to run on discourse OOPS page

Hi

We had custom javascript written in discourse api events like onAppEvent, decorateWidget, onPageChange,etc…,. The above api events are working fine on discourse pages. But, those discourse api events are failed to execute the scripts on “OOPS” page. So we tried to create own discourse api event using the below code to execute,

<script type="text/discourse-plugin" language="javascript">
   if (!('Discourse' in window)) {
        window.Discourse = {};
    }
    if ('Discourse' in window && !('_registerPluginCode' in window.Discourse)) {
        // Make this a noop
       
        window.Discourse._registerPluginCode = function() {};
        // Our scripts
}
</script>

When tried this above script, i am getting the error as “Uncaught TypeError: Cannot read property ‘lookup’ of undefined” . I don’t know why it’s getting failed on getting themes from discourse.

Refer the below screenshot,

How to overcome the above error to execute custom scripts on OOPS page ?