Button working from the the second click

My custom button function is working from the second click, why this is happening?

frappe.ui.form.on("Maintenance Visit Purpose", "orcamento", function(frm){
	cur_frm.cscript["orcamento"] = function(doc, dt, name){
		alert("worked")
	}
});

I noticed also when clicking on breadcrumbs, can u confirm?

How can I check that?

Link in the upper left …just on the right of E logo …i.e. module name (Accounting, Stock etc)

Maintenance > Maintenance Visit
My script is to Maintenance Visit Purpose, maybe is that?

Yup, enter in one doc, once loaded click on maintenance visit link. I don’t think so, probably a small bug when using in develop mode and bench start

The problem happens when I clear the cache and then click on the button…
The second click is working, awkward

It only happen when clicking your custom button? Or even others?

Just my custom button

Can you try:

frappe.ui.form.on("Maintenance Visit Purpose", "orcamento", function(frm) {
		alert("worked")
	}

Worked!
Thank you @JoEz