Identify that jira gadget is used within confluence

Hi,

We currently use a Javascript Proxy that depending on the environment will decide what is the correct way to do the rest requests. For DC we are using fetch, Cloud is AP.request etc. (We currently try to avoid the usage of jquery)
If a customer tries to use our gadget within confluence, it initially fetch is using the wrong baseUrl and we had to use the AJS.$.ajax. After some time (new jira / confluence versions) our initially working condition failed to identify that the jira gadget within confluence and we switched to something different. It feels like this happened around 3-4 times
As of now our check is failing again and maybe someone knows a more reliable way to identify that your jira gadget is used within confluence?
Our Last approach was this one:

	AJS.Meta.getAllAsMap()['confluence-flavour'] !== undefined ||
	AJS.Meta.getAllAsMap()['is-confluence-admin'] !== undefined ||
	AJS.Meta.getAllAsMap()['space-key'] !== undefined ||

which is not working any longer as AJS.Meta does return only a single entry.
After some try & error with the developer console I found out that AJS.gadget with a getBaseUrl function seem to exist only when used from confluence.
Does someone know more about it or are there better ways to identify between the external / internal use of a gadget?

1 Like

Hey m.herrmann,

Jira gadgets in Confluence can be weird, but let’s simplify things. To reliably check if your Jira gadget is hanging out in Confluence, give this snippet a shot:

const isConfluence = AJS.gadget && typeof AJS.gadget.getBaseUrl === 'function';

This little code gem should do the trick. Keep it simple and give it a whirl. If you hit any bumps, we’re here for more brainstorming. Cheers to straightforward solutions!

1 Like