Trying to use web resource for js

Starting out jira development and trying to have js trigger on every page.
Created a skeleton plugin and added some js to the resource but nothing is happening. Wondering what i’m doing wrong.

Atlassian-plugin.xml:

${project.description} ${project.version} images/pluginIcon.png images/pluginLogo.png
<!-- add our i18n resource -->
<resource type="i18n" name="i18n" location="jsPlugin"/>

<!-- add our web resources -->
<web-resource key="jsPlugin-resources" name="jsPlugin Web Resources">
    <dependency>com.atlassian.auiplugin:ajs</dependency>
    
    <resource type="download" name="jsPlugin.css" location="/css/jsPlugin.css"/>
    <resource type="download" name="jsPlugin.js" location="/js/jsPlugin.js"/>
    <resource type="download" name="images/" location="/images"/>
    <context>jsPlugin</context>
</web-resource>

jsPlugin.js:
document.body.style.backgroundColor = “red”;

Hi and welcome to atlassian development world.

You need to put
<context>atl.general</context>
instead of
<context>jsPlugin</context>
if you want the script to be loaded under administration section add one more context:
<context>atl.admin</context>

Please see here about context.

I removed jsPlugin and added atl.general
It’s still not working and this also made it so the left side of the project panel doesn’t load.

It should not have any impact on left side unless your have some JavaScript that interferes with Jira scripts.

Please check that your script is included to the page. As I remember by default it’s batched into batch.js but you can just try to search for some unique lines that you have in you script.

alright. Started over again. Created a skeleton addon with atlas-create-jira-plugin
But still getting the issue where my js isn’t showing.

I now have:
atl.admin

and my js file only has this for testing:

document.body.style.backgroundColor = "red";

@kjacobs,

You will need the context to specify when JIRA will load your javascript, for testing you can use

<context>atl.general</context>

I’m wondering if maybe your code is running before the page be rendered;

Can you try below example?

AJS.toInit(function() {
 alert('hello world')
});

This worked! Thanks! Having an new issue now lol

1 Like