victorwesterlund.com/public/assets/js/modules/Logging.mjs
Victor Westerlund 5c07d93535
Version 9.0 (#17)
Release of version 9.0.0
2021-09-20 11:37:36 +02:00

34 lines
No EOL
645 B
JavaScript

// Victor Westerlund - www.victorwesterlund.com
class Logging {
constructor() {
this.endpoint = "/log/";
this.data = new URLSearchParams();
document.addEventListener("visibilitychange",() => {
if(document.visibilityState === "hidden") {
this.send();
}
});
this.log("foo","bar");
}
log(key,value) {
this.data.append(key,value);
}
send() {
const send = navigator.sendBeacon(this.endpoint,this.data);
if(send !== true) {
const url = this.endpoint + this.data.toString();
fetch(url).catch(response => console.log(response));
}
}
}
export default class Log {
constructor(value,key = "u") {
// WIP
}
}