Skip to content

Conversation

strangelookingnerd
Copy link
Contributor

#266

Testing done

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@strangelookingnerd
Copy link
Contributor Author

For reasons I do not yet understand, the copy.js is not properly loaded. It seems to be blocked by something when used in badge.jelly. It works just fine in other places.

@strangelookingnerd strangelookingnerd linked an issue May 22, 2025 that may be closed by this pull request
@strangelookingnerd strangelookingnerd added enhancement New feature or request help wanted Extra attention is needed labels May 22, 2025
@strangelookingnerd
Copy link
Contributor Author

@janfaracik IIRC you made a great effort in modernizing the build history widget. Would you by chance have any idea what may cause my approach here to not work?

@@ -26,6 +26,7 @@ THE SOFTWARE.
<?jelly escape-by-default='false'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
<st:adjunct includes="com.jenkinsci.plugins.badge.assets"/>
<st:adjunct includes="com.jenkinsci.plugins.badge.copy"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mawinter69
Copy link

mawinter69 commented May 26, 2025

I think scripts are not loaded when you insert html into the dom with innerHTML as it is done by the widget.
See https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML#security_considerations
Not sure if this also applies to <script src="..."/>
btw the css is loaded each time the widget is reloaded and adds another line to the html tree in the header
image

@strangelookingnerd
Copy link
Contributor Author

As @daniel-beck pointed out it seems to be

Regression in 2.463, presumably due to jenkinsci/jenkins#9148.

I can confirm that the scripts load fine before this change.

btw the css is loaded each time the widget is reloaded and adds another line to the html tree in the header

Interessting. I would not know how to prevent that from happening tho.

@strangelookingnerd
Copy link
Contributor Author

I gave it another go but for the life of me can not find out what's blocking my script. There is no error anywhere and the CSS file is loaded just fine.
None of the changes in jenkinsci/jenkins#9148 seem suspicious to me.
Kindly asking @janfaracik for some insights.

@mawinter69
Copy link

Just a theory in the old widget after loading the div with the fetched content it was running Behaviour.applySubtree(div)
The new widget is not calling Behaviour.applySubtree. You would need to check if adding that call in core fixes the problem.

@janfaracik
Copy link
Member

Sorry for the delay, taking a look :)

@janfaracik
Copy link
Member

Hmm also struggling to figure out why it's not working. I've made some changes to core but still couldn't get it working.

Would it be possible/advisable to add an invisible action to the page to load in 'copy.js'?

@mawinter69
Copy link

Also with 2.463.3 it only works when the badge is already present on initial page load. When the job has no old builds and you click build now once the build appears in the history the copy to clipboard doesn't work here as well.
With the change in core, the history is always loaded async and so the js is not loaded.
The brings me back to my initial assumption that javascript isn't loaded when it is only included in a string assigned to innerHTML

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable Click-to-Copy Functionality for text Badges
4 participants