You are here: Home / Projects / OSADL Toolbox / 
2023-02-03 - 23:36

JavaScript Licensing

Standard information obligations of Open Source licenses

Most Open Source licenses require that the license text and copyright notices be delivered to the recipient along with the software. This undoubtedly also applies in the event that Open Source software is copied to a user's computer when a web page is loaded and executed locally, as is regularly the case with software written in JavaScript, for example. Since it is not evident how this is best achieved, this application note describes a possible implementation and contains a practical realization.

Interpretation of "to be delivered along with the software" in a scenario where a JavaScript snippet is downloaded from a web server to the local browser

Strictly speaking, "to be delivered along with the software" means that the operator of the web server from which the JavaScript software is provided must actively deliver the associated licensing information. In this interpretation, it is not sufficient to provide a link to this information located elsewhere. (Please note that we deliberately do not pursue here the question to what extent this interpretation is generally accepted and in how many websites this view has been actively implemented.) The said active delivery can be implemented, for example, with a transfer of the license information file that automatically is triggered when the web page is loaded. As soon as this file is available locally, a hyperlink is activated in which reference is made to the license information. When this hyperlink is clicked, a text window opens that displays the local copy of the license information. This functionality can also be used to confirm that the license obligations have actually been fulfilled.

JavaScript class to trigger the download of license information to the visitor's computer

The JavaScript class XMLHttpRequest() is used for this purpose. The load function of this class is provided with the name of a function that will receive the downloaded text, in the example it is the reqListenerText() function. This function then equips a text string with a hyperlink to the downloaded text – but this can only happen, if the text was actually received. The licensing information of this example JavaScript snippet that is licensed under the MIT license was generated with the Scancode toolkit. The actual license text was manually inserted into Scancode's output, and everything together was made available on the server from where the script can download it.

Example of what a link to the licensing information of a JavaScript snippet might look like and how it works

Click on the hypertext below to see how the implementation works.

HTML and JavaScript code implemented behind the hypertext link above

The HTML hypertext uses the default style of an anchor element. Initially, its onclick() callback refers to an error message to indicate that the licensing information is not yet available. The JavaScript part calls XMLHttpRequest() and installs the listener reqListenerText(). When the download is completed which is indicated by a call to the listener, the onclick element of the hypertext is replaced by the display function showLicenseInfo() which opens, when called, a new window and displays the downloaded licensing information in it.

 
<a id="licenseref" onclick="alert('Sorry, the licensing information was not yet downloaded.');" title="The holders of right have granted permission to copy and distribute this software to you provided that we also give license texts and copyright notices to you. We did so when the page was loaded. Click here to verify.">
All license texts and copyright notices
</a>
<script>
// This software is licensed under the MIT License.
// Copyright (c) 2022 Open Source Automation Development Lab (OSADL) eG, author Carsten Emde
 
var licenseInfo;
var licenseWindow = null;
 
function showLicenseInfo() {
  var left = window.screenX + 32;
  var top =  window.screenY + 96;
  var height = window.innerHeight - 128;
  var width = 1216;
 
  if (width > window.screen.width)
    width = window.screen.width;
  if (licenseWindow == null || licenseWindow.closed) {
    licenseWindow = window.open('', '', 'left=' + left + ', top=' + top + ', width=' + width + ', height=' + height);
    licenseWindow.document.open();
    licenseWindow.document.write(licenseInfo);
    licenseWindow.document.title = "Local copy of licensing information";
    licenseWindow.focus();
    licenseWindow.document.close();
  } else
    licenseWindow.focus();
}
 
function reqListenerText() {
  document.body.style.cursor = 'default';
  licenseInfo = this.responseText;
  licenseRef = document.getElementById('licenseref');
  licenseRef.onclick = function() { showLicenseInfo(); return false; };
}
 
var tReq = new XMLHttpRequest();
document.body.style.cursor = 'wait';
tReq.addEventListener('load', reqListenerText);
tReq.open('GET', 'https://www.osadl.org/js-licensing/licenses.html');
tReq.send();
</script>

Real-world implementation

Since the Jitsi Meet Open Source video conferencing system heavily relies on a wide variety of JavaScript libraries that are downloaded to a user's computer when this software is used, the licensing information of these libraries must also be downloaded. In OSADL's instance of Jitsi Meet, this is implemented using the above given application note. The hyperlinked text string "All license texts and copyright notices" is located at the top of the main window as shown in the below preview image (enlarge). Licensing information was generated here as well using the Scancode toolkit, and the respective license texts were appended manually to its output. Click on the below preview image to go to the landing page of OSADL's Jitsi Meet instance, if you want to try it out.

OSADL's Jitsi Meet instance