Getting ReferenceError AP is not defined

Probably related to Using AP.request to fetch content from the Confluence host has recently stopped working?

Same issue for us, any known solutions?

1 Like

No solution unfortunately. We live with this error :frowning:

2 Likes

See Please add a CDN mirror for all.js
That thread is a request for Atlassian to provide a CDN fallback/mirror for all.js

1 Like

As Ture said, we are having this same problem on occasion after switching to pulling all.js from CDN. We haven’t figured out for sure if it’s a CDN failure or not, but having a fallback if it is failing to load from the CDN would be valuable, as that’s not an uncommon practice.

Another vendor said that they worked around the problem here by using a custom async wait function that would test for the presence of the AP global in a loop to give it some time to init, and that this approach eliminated the errors for them. Looking at the all-debug.js sources, I don’t see any way that the global couldn’t be there immediately if the script finishes loading without error, though, and we aren’t seeing any other errors being thrown from the AP script itself. I will try this approach, but am skeptical that it will help.

The error rate we are observing is relatively low (maybe 1-20 per day out of 10k+ total requests), but no errors is better than some errors :wink: Most often it occurs on Windows 10 with Chrome, but combinations involving MacOS and Firefox have been observed as well.

@dmorrow
We are seeing that some AP related javascript is not loaded. The browser console gives errors like:

> ReferenceError: "_AP is not defined"
>     <anonymous> https://d2oo471t4e338f.cloudfront.net/XXXXXXX.atlassian.net/wiki/s/d41d8cd98f00b204e9800998ecf8427e-CDN/-659307766/h/5295cb211c06107e38861d05bc31dea1/_/download/batch/com.atlassian.plugins.atlassian-connect-plugin:iframe-host-utils-v5/com.atlassian.plugins.atlassian-connect-plugin:iframe-host-utils-v5.js?externals=__local-default__:5
> com.atlassian.plugins.atlassian-connect-plugin:iframe-host-utils-v5.js:1:96
>     WRMCB https://d2oo471t4e338f.cloudfront.net/XXXXXX.atlassian.net/wiki/s/d41d8cd98f00b204e9800998ecf8427e-CDN/-659307766/h/5295cb211c06107e38861d05bc31dea1/_/download/batch/com.atlassian.plugins.atlassian-connect-plugin:iframe-host-utils-v5/com.atlassian.plugins.atlassian-connect-plugin:iframe-host-utils-v5.js?externals=__local-default__:1
>     <anonymous> https://d2oo471t4e338f.cloudfront.net/XXXXX.atlassian.net/wiki/s/d41d8cd98f00b204e9800998ecf8427e-CDN/-659307766/h/5295cb211c06107e38861d05bc31dea1/_/download/batch/com.atlassian.plugins.atlassian-connect-plugin:iframe-host-utils-v5/com.atlassian.plugins.atlassian-connect-plugin:iframe-host-utils-v5.js?externals=__local-default__:6

And many more of these errors. That makes our addon not work properly. Somehow this error seems related to cloudfront failing to load resources.

Edit: this happens in Confluence Cloud

1 Like

Hi @marc,
Are you loading all.js from https://connect-cdn.atl-paas.net/all.js before you get this error? The reason I ask is because all.js defines the _AP object (you can see the source code at https://connect-cdn.atl-paas.net/all-debug.js).
Regards,
Dugald

@dmorrow
Yes, I’m loading all.js before. Actually I’m using atlassian-connect-express which does this automatically.
The problem happens intermittently, and sometimes with my customers. I don’t know how often, as the problem is on the client side.

2 Likes

We still observe the problem on our side.

There was another post where other vendors claimed they are affected too. Someone suggested race condition and use of the technique to postpone AP usage until it is defined.

1 Like

@marc and @jack,
There could be different things going on here, but importantly both are issues affecting your customers in production. Could you please raise a bug report in the Developer Service Desk and mention this thread. I’d like to work with you to investigate further

1 Like

Hi @dboyd ,
related thread? https://community.developer.atlassian.com/t/ap-jiraservicedesk-is-undefined/35737

@dboyd, thank you for looking into this.

I’ve raised DEVHELP-4182

1 Like

We are still experiencing this as well when loading from the CDN URL. I’ve posted about it both in this thread and elsewhere, but with no response.

If it possible to add me to the new DEVHELP ticket as well so I can follow along and possibly offer more information? It’s a frustrating problem to know that our users often cannot use our apps because of this, yet we take blame for it.

I would love to have more than one CDN URL available, also, so that when network conditions cause the primary to fail to load, we could fallback to a non-Cloudfront mirror to improve chances of the app loading successfully. Here are other places I have raised this with no response:

related thread? https://community.developer.atlassian.com/t/ap-jiraservicedesk-is-undefined/35737

No, the above incident was not related.

@jack @BobBergman @george1
The _AP loading issue is now tracked at https://jira.atlassian.com/browse/CONFCLOUD-69391 .

1 Like

It looks like that issue is different than the one that the OP and I are talking about. Our issue as raised on the forums is different than this — we simply see that AP is not defined after loading the script from the new CDN URL some small percentage of the time (like 1 in every few hundred). Some customers appear to experience a higher rate of the issue than others. I’ll open a new DEVHELP today.

1 Like

Our problem occurs in Jira and is more than 2 years old. It has nothing to do with new Confluence editor.

I will update the DEVHELP ticket with more information.

Ours is not specific to the new confluence editor, but appears related to loading the script from the new cdn url, possibly specific to certain customer network topologies.

These could all be unique issues, but the title of this post at least matches the error we are seeing :slight_smile:

3 Likes

If you are using any script file and getting “Uncaught ReferenceError:” which means ‘x’ is either a variable or a method which you are trying to use before declaring it using var keyword. This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in your current script or scope otherwise , it will endup throwing this ‘x’ is not defined error . This usually indicates that your library is not loaded and JavaScript does not recognize the ‘x’.

To solve this error: Load your library at the beginning of all your scripts.

There can be multiple other reasons for this issue:

  • Path to CDN library you included is not correct
  • The library file is corrupted
  • Working offline
  • Conflict with Other Libraries

@lingmaaki,

The AP is an object in the Atlassian library, and the problem is intermittent.