Solution
This is an expected behaviour. Data Navigation session will not be closed automatically when the browser or its tab is closed. The developer has to capture the close browser event using
onbeforeunload event to close the session programmatically.
Simple HTML below can be used as a reference to understand how this can be implemneted
<!DOCTYPE html>
<html lang="en">
<body>
Hello world!
</body>
<script>
var id = "";
window.addEventListener("beforeunload", (event) => {
event.preventDefault()
event.returnValue = '';
closeSession();
});
window.addEventListener("load", (event) => {
alert("Welcome. Datafinder session will be created next.");
createSession();
});
function createSession(){
var data = JSON.stringify({"variables":{"$URL":{"stringArray":{"values":["corbaname::#DataFinder_Name.ASAM-ODS"]}}}});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
id = this.getResponseHeader("Location").split("/").pop();
alert("Session created: " + id);
}
});
xhr.open("POST", "https://SystemLink_Server_IP_Address/ni/asam/ods");
xhr.setRequestHeader("Accept", "application/x-asamods+json");
xhr.setRequestHeader("Content-Type", "application/x-asamods+json");
xhr.setRequestHeader("X-NI-Auth-Method", "Basic");
xhr.setRequestHeader("Authorization", "Basic Base64_Encoded_Username:Password");
xhr.send(data);
}
function closeSession(){
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("DELETE", "https://SystemLink_Server_IP_Address/ni/asam/ods/ni/asam/ods/" + id);
xhr.setRequestHeader("Accept", "application/x-asamods+json");
xhr.setRequestHeader("Content-Type", "application/x-asamods+json");
xhr.setRequestHeader("X-NI-Auth-Method", "Basic");
xhr.setRequestHeader("Authorization", "Basic Base64_Encoded_Username:Password");
xhr.send();
}
</script>
</html>