prodigyscriptloaded does not fire

(edit: sorry for formatting, but when I copy paste code in this box, select it and click “prereformatted” it turns everything in one long line and in general this edit is not usable to paste code eg it pastes extra newlines )

from this example Custom Interfaces · Prodigy · An annotation tool for AI, Machine Learning & NLP , in the custom script below I can see “here” in the browser console , but never “prodigyscriptloaded”

console.log('here')

/* this does not fire below */

document.addEventListener('prodigyscriptloaded', loadEvent => {

console.log('prodigyscriptloaded')

if (loadEvent.detail.url.endsWith('sentiment-refresh.js')) {

// only run this code 1 time when the current script

// ("sentiment-refresh.js") has finished loading

document.addEventListener('prodigyanswer', answerEvent => {

const { answer, task } = answerEvent.detail

console.log('The answer was: ', answer)

})

document.addEventListener('prodigysave', event => {

/*const { answer, task } = event.detail*/

console.log('Saved: '/*, answer*/)

})

}

})

recipe is also as in example like this

return {

    "dataset": dataset,

"stream": stream,

"view_id": "blocks",

"config": {

"blocks": [

            {"view_id": "choice"},

# Load custom Input for New Model Name

            {

"view_id": "html",

"html_template": (CWD / "sentiment-refresh.html").read_text(),

            },

        \],

# Load custom JavaScript file.

"javascript": (CWD / "sentiment-refresh.js").read_text(),

    },

"event_hooks": {

# add event handler endpoint at: `/event/refresh_model`

"refresh_model": refresh_model_event_handler,

# add event handler endpoint at: `/event/new_dataset`

"new_dataset": new_dataset_event_handler

    },

}

repro is here prodigy-bugs/javascript-events at main · wildfluss/prodigy-bugs · GitHub

PS i could not paste same repro message to different bug threads :frowning: oh my

guys you have a typo in example code , in bundle.js its “dispatchEvent(new CustomEvent("prodigyscriptload",” and in example code its prodigyscriptloaded :slight_smile:

but prodigyscriptload does not fire anyways

Hi @ysz,

Thanks for the heads about the typo in docs - that's already corrected.

As for the prodigyscriptload not firing:

Currently, prodigyscriptload only fires when the JS is loaded via actual scripts either local or external i.e. via javascript_dir or javascript_urls config options and not for embedded JS as is the case for your example.

The main thinking here is that the inline scripts don't technically load. They execute synchronously and immediately when the browser parses them. External scripts with src attributes load asynchronously, they have an actual load phase (network request, parsing, execution), which makes a "load" event meaningful.

That said, we appreciate that this distinction results in inconsistent dev experience (in particular that the details of the loading methods were not documented).
We'll unify all three loading methods wrt to prodigyscriptload event in the upcoming patch. We'll ping you here when it's out.
Thanks again for the report!

Also, a small tip re incline code editing: the editor let's you toggle between the markdown editor and "new" rich text editor (the very first toggle on the LHS of the editor toolbar) - I found it is much easier to format code in the "old" markdown editor you just include it in triple backtics optionally providing the language for syntaxt highlighting e.g. js[...].
I believe the rich text editor is on by default.

Hi again @ysz,

Please see the update on your issue here: Custom javascript and css is not executing if the user is accessing prodigy when all tasks are already complete - #8 by magdaaniol