Run a JSObject function on page load


I’m trying to build a custom authentication just like this: How to Implement Custom Login/Authentication in Appsmith - YouTube

The only difference is that I will not have a login form but a token in the url.
With this token I will call a and API that wil return an OK and a JWT token.

I need to run this query on page load; but also need co catch the ok message, store data using

I know it’s possible to run an Query on page load but how can I catch the error or success msg and do further things with it.

I tried using a Container. Visible property but that does not allow access
It works fine witha Button.onClick event but I want the redirect to be automatic, without a click.

Here is my code from Container.Visible

{{ => showAlert('ok','success'), () => showAlert('not ok', 'errror'))}}

this one works



        return false;



this one doesn’t
(function(){ => showAlert(‘ok’,‘success’), () => showAlert(‘not ok’, ‘errror’))
return false;


Unfortunately, today, functions defined in JSObject cannot be called on page load. This is something we are working on. You can track the issue here - feat: Settings js editor by ApekshaBhosale · Pull Request #9984 · appsmithorg/appsmith · GitHub

You can however pass parameters to the run() function - Query - Appsmith

You may simulate this by having a small, discrete, iframe, that loads a transparent html from your server that has a small js snipet to call parent.postMessage().
You then configure the iframe onMessageReceived property to run a JS function, that starts your app logic.
There are other difficulties like errors on objects whose data binding is not initialized, but for now it seems to work just the same.
An example of a small html file you can use:

<meta http-equiv="Cache-control" content="no-cache">
<style type="text/css">
  html {background:none transparent;}
  function init() {
        parent.postMessage("hello", "*");
<body onLoad="init">
  <div id="content"></div>