Hi Daniele, just an update because I am working on custom element recently.
The JS function defined in public $scripts
will be auto triggered in bricks iframe when your custom element render.
If you saw it called twice on bricks builder initial load, it might due to 2 custom elements in the builder and not because of DOM loaded twice.
I still think that the second “JQMIGRATE: Migrate is installed, version 3.3.2” coming from iframe.
======My experiment=====
My element
public $scripts = ['itchyLog']; // Enqueue registered scripts by their handle
public function enqueue_scripts() {
wp_enqueue_script( 'itchy-log' );
}
My js handler itchy-log registered earlier in wp_enqueue_scripts hook, dependency on bricks-scripts
wp_register_script(
'itchy-loop',
get_stylesheet_directory_uri() . '/itchy-log.js',
[ 'bricks-scripts' ],
filemtime( get_stylesheet_directory() . '/itchy-log.js' )
)
This is the content of my itchy-log.js
function itchyLog() {
const timeStamp = '[' + new Date().toUTCString() + '] ';
console.log(`${timeStamp} itchyLog`)
}
document.addEventListener("DOMContentLoaded", ()=>{
const bircksIsPreview = window.location.href.includes('brickspreview')
if( bricksIsFrontend ) {
console.log(`This is in frontend`)
} else {
if( bircksIsPreview ) {
console.log(`This is in preview`)
} else {
console.log(`This is in main builder`)
}
}
})
Once I add my 2 custom element, refresh page in builder mode, dev tools console tab looks like this:
- JQMIGRATE running in main builder
- My JS DOMContentLoaded, detected currently in main builder
- I assumed End in main builder.
- JQMIGRATE running in builder iframe
- MY JS DOMContentLoaded, detected currently in iframe preview
- 2 elements rendered, trigger itchyLog function, console log out the time
- I assumed End in preview iframe.
In actual frontend, it just looks like this:

- MY JS DOMContentLoaded, detected currently in frontend
- End
PS: $scripts
only the functions to be auto running in Builder Iframe upon rendering, in actual frontend, still need to trigger your own function manually.
Hope this experiment make sense. 