AP.request is undefined for publishing metric results

I have seen other posts mention this issue for their Apps, but the issue in this context is regarding Synthetic Testing.

We would like to use the Atlassian Connect JS API)to send a request to the Metrics API.

The all.js script is included in our App, and appears inside of our iFrame as expected.

Our synthetic test framework has already done the following:

  1. Logged into the instance and navigated to the App.
  2. Switched context to the iFrame of the Atlassian Connect App.

At this stage, the following request is attempted:

window.AP.request({
            url: `/rest/atlassian-connect/latest/addons-metrics/${appKey}/publish`,
            type: 'PUT',
            contentType: 'application/json',
            data: JSON.stringify([{
                metricsType: 'SYNTHETIC',
                status: testStatus
            }])
        })

resulting in the error:

frame.evaluateHandle: TypeError: Cannot read properties of undefined (reading 'request')

We have attempted this for both Playwright and WebdriverIO, both times Window.AP is undefined, preventing requests to be called.

Findings:
As far as I can tell, there are multiple window objects in play:

  • Calling window.AP from the App in a normal browser returns undefined, but has access to window objects such as window.JIRA.
  • Calling window.AP from the App’s iFrame in a normal browser returns the window.AP object (as expected?), but does not have access to the parent pages window objects such as window.JIRA.

This would lead to knowing that both Playwright and WebdriverIO Javascript evaluation to access window objects uses the Pages window object, without a way to use the iFrames window object (despite being inside the iFrame context).

Should window.AP be available after switching to the Apps iFrame context?
If not, is there a known method to access the JS API from within the App via a Synthetic Testing Framework?

Should window.AP be available after switching to the Apps iFrame context?

@DennyMiller I imagine so. But at the very least, the iframe must have loaded all.js. Perhaps - I haven’t double checked this - the iframe’s postMessage bridge must also have been established. At least, until that happens, the JavaScript API methods wouldn’t work.

Are yo making sure that this has happened before you try to evaluate window.AP?

Are yo making sure that this has happened before you try to evaluate window.AP ?

The test has already waited for the iFrame to appear, switched into the iFrame context, then waited for specific App content to appear. all.js should have had enough time to be fully loaded, but i’ll run a sanity check that waits a minute for all page resources to load.

Thank you! Somehow it seems that despite thinking it was enough time, waiting for window.AP works!
(For Playwright, frame.waitForFunction(() => window.AP); is enough for this)

1 Like