How to add javascript add on every page?

Good Day. I would like to ask how to add javascript add on every page?

I wanted to add livechat.js javascript to my owncloud site.

I copied the script and added the code on
core/templates/layout.guest.php
core/templates/layout.base.php
core/templates/layout.user.php
before the closing head

It seems not working.
HERE IS THE SAMPLE CODE OF livechat.js:

//code

I tried another script like pop up javascript just to test if javascript really works on every page and it does!!!.

HERE IS THE JAVASCRIPT I TESTED THAT WORK:

//code
window.alert("sometext");

Please Help!

In your appinfo/app.php file just add this:

\OCP\Util::addScript('yourappname', 'livechat');

Thankyou for your response, @PVince81

with your help i got a step ahead. could you help me with the error as shown in the screenshot

Hmmm, I don't how to prevent the CSP issue.

@butonic do you know ?

@butonic, Please help me sorting this issue. Thank you in Advance

The following hint [1] from @kpswalin in [2] might give you some pointers.

[1]

[2]

  1. Your js file contains an html comment tag and a script tag. They should be removed, because you are loading a js file, not an html file.
  2. CSPs can be changed by apps. See this gist for an example showing how to add custom Content Security Policies: https://gist.github.com/butonic/4e6d050b778866e3aa99af14d9474613 Also see the initial PR: https://github.com/owncloud/core/pull/21989#issue-129480520