Hello folks!
New app developer here, trying to understand something basic. Please feel free to point me to the right links.
Our full-screen app is going to be essentially one HTML page, with an IFrame tag and some JavaScript. I have this working now as a private app. The IFrame properly shows my page in my external site.
However, I want to pass in the client object into my IFrame with PostMessage(), and am puzzled about what I’m seeing in the app.js behavior.
My app.js is like so…
var appClient = null;
const version = 17;
app.initialized().then(
async function(client)
{
appClient = client;
console.log(`Freshdesk app v${version} initialized() event fired`);
//console.log("appClient: " , JSON.stringify(appClient, null, 2));
appClient.events.on("app.activated", onAppActivated);
appClient.events.on("app.deactivated", onAppDeactivated);
},
function(error)
{
console.log(error);
}
);
function onAppActivated() {
try {
console.log("Any chance this console.log will fire?");
console.log(`Freshdesk v${version} onAppActivated() event fired`);
console.log("nope!");
// IGNORE THE REST...PROCESSING NEVER GETS THIS FAR...
const iframe = document.getElementById('iframe');
if(!iframe) {console.log("iframe not found"); return;}
console.log("iframe: " , JSON.stringify(iframe, null, 2));
if(!appClient) {console.log("appClient not found"); return;}
iframe.contentwindow.postMessage(appClient, 'https://www.mywebsite.com');
console.log("fired postMessage() to iframe");
} catch (error) {
console.log("error: ", error);
}
}
async function onAppDeactivated() {
console.log("Freshdesk onAppDeactivated() event fired");
}
Both initialized()
and onAppActivated()
are firing. I update the version
variable with each update, so I can confirm that I’m always running the newest version.
But this is what the console.logs give me in my DevTools console:
Freshdesk app v17 initialized() event fired
Freshdesk v17 onAppActivated() event fired
Notice that it fires the second console.log statement in onAppActivated()
but not the first, and not the third (or any following).
In all my years of JavaScriptery, I have never seen a routine that plucks one command out of the batch, ignores the rest, and doesn’t throw an error to be polite.
What am I doing wrong?
Many thanks!