Current issue viewers in Forge

Hello,

I stumbled across this project Bitbucket and wonder is it possible to make that in Forge?

I know I can execute some js code in module issueViewBackgroundScript. Also I think I can detect issue viewed event but I don’t know how to handle moment that user leaves the issuse.

I thought maybe that can be done this way:

  1. register issue viewed event and store that in some place like storage or issue properties
  2. in issueViewBackgroundScript listen for some js leaving event
  3. if event detected remove entry from views storage

I tried that Top 3 ways to easily detect when a user leaves a page using JavaScript - DEV Community but it hasn’t worked (yet).

Can someone recommend if that thinking is ok and/or how to handle that better way?

Cheers

Hi @ITKobe,

The three methods mentioned in the article “Top 3 ways to easily detect when a user leaves a page using JavaScript - DEV Community” will work well for detecting events at the top level of the page (parent document-level events). However, when using issueViewBackgroundScript, it runs in a hidden iframe that doesn’t have access to the parent window’s events. It’s also highly unlikely that Atlassian would forward these events to all Custom UI iframes.

Instead, I recommend setting up a timer in your JavaScript code that periodically sends “still alive” messages to the storage or entity properties, updating the “last visit time” for the user accordingly. When someone opens your panel, you can check the last visit time of all visitors, and if it’s within a defined threshold (e.g., a certain number of seconds), you can assume the person is still online.

Hope this helps!

2 Likes

@AndreiPisklenov thank you for an explanation and suggestion how to handle that. Sounds promising and I definitely gonna try this!

1 Like