Corredor client script on page-load

Is there anyway to run JS on the client side without modifying the frontend application?

I would like to do some basic things (such as add keyboard shortcuts or inject some css) that seemingly could done using short corredor scripts.

2 Likes

This is officially not supported, however I found a hack that can make this work!

Apparently metric components inject javascript onto the page every time they refresh.

Here are the steps to get JS to run on page load.

  1. Add a metric component to the page (you can make it as small as possible so it doesn’t disturb the UI)
  2. Choose a module that has few records (or create an empty module just for this purpose) in order to decrease initial load time
  3. Choose any field for the metric, I chose count
  4. This is where the magic happens. In the transform value (whose current implementation injects your JS into the page), put the script below.
(()=>{
if(!window.unlikelyPrefiCustomCortezaJS){
    const onLoad = ()=>{
        console.log('This will be loaded once per page, on metric refresh, which happens automatically on page load')
    }
    window.unlikelyPrefiCustomCortezaJS=onLoad;
    window.unlikelyPrefiCustomCortezaJS();
}})()

Change the console.log code to whatever custom JS you want to run on page load.

1 Like