Forma Developer Forum
Welcome to Autodesk Forma Developer Forum. Share your knowledge, ask questions, and explore popular Forma API topics.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is there a way to get an event when the Extension unloads?

Message 1 of 3
181 Views, 2 Replies

Is there a way to get an event when the Extension unloads?

Hey Forma Team, 

Could we possibly get an subscription event for when the Extension unloads?
Meaning when the user exits the extension it would be very helpful to do some cleanup on our side
Basically an event listener when the user clicks the exit arrow would suffice. 



I have been doing some tests with the 

onEmbeddedViewStateChange() createSubscription() and onStateChange() methods of the iframeMessenger but none have yielded any results.

many thanks

Message 2 of 3
in reply to: iklimis

Hi Giannis
Close events is unfortunatly a very hard problem to solve. There is the happy and the hard path to the problem of when an Iframe unloads. And the short answer is that we can't reliably fire off "before-iframe-close" events that would in every case allow you to for example save on a "close" event. 

We can however allow the happy path, by giving the IFrame one event before closing it using the exit arrow. But if the event doesn't fire when the user for example closes the Forma browser tab, is it still useful?

I would therefore love to hear the usecase for this. What are you cleaning up when unloading the extension?

Message 3 of 3
in reply to: iklimis


Thank you for your detailed and insightful explanation. I must say I completely agree. 

The use case behind this post was that when we create a geoJson and add it as a Forma Element, we want the user to modify the selected geoJson. When the user exits the extension we would like to delete this Element programmatically - which as of now we can't (we can use hideElement() but the object re-appears as the user exits the ext).
So the first thought was to replace the geoJson with an empty one (so it seems as it is deleted) the moment the user exits like on an 'before-iframe-close'but as you pointed out what if the user closes the browser? Same result right? Can't safely depend on that event.


So, basically another approach using localStorage was taken. Save the rendered geoJson's path in storage and if the user closes the browser (or the extension) unexpectedly, next time check if the path exists and continue using that element path and its geometry...)  and continue the process from there on.


Thanks again!



Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report