The f5 loadbalancer is injecting this script to my index page:
<script id="f5_cspm">
(function () {
var f5_cspm = {
f5_p: 'someencodedtext',
setCharAt: function (str, index, chr) {
if (index > str.length - 1) return str;
return str.substr(0, index) + chr + str.substr(index + 1);
},
get_byte: function (str, i) {
var s = (i / 16) | 0;
i = (i & 15);
s = s * 32;
return ((str.charCodeAt(i + 16 + s) - 65) << 4) | (str.charCodeAt(i + s) - 65);
},
set_byte: function (str, i, b) {
var s = (i / 16) | 0;
i = (i & 15);
s = s * 32;
str = f5_cspm.setCharAt(str, (i + 16 + s), String.fromCharCode((b >> 4) + 65));
str = f5_cspm.setCharAt(str, (i + s), String.fromCharCode((b & 15) + 65));
return str;
},
set_latency: function (str, latency) {
latency = latency & 0xffff;
str = f5_cspm.set_byte(str, 40, (latency >> 8));
str = f5_cspm.set_byte(str, 41, (latency & 0xff));
str = f5_cspm.set_byte(str, 35, 2);
return str;
},
wait_perf_data: function () {
try {
var wp = window.performance.timing;
if (wp.loadEventEnd > 0) {
var res = wp.loadEventEnd - wp.navigationStart;
if (res < 60001) {
var cookie_val = f5_cspm.set_latency(f5_cspm.f5_p, res);
window.document.cookie = 'f5avr0138950615aaaaaaaaaaaaaaaa_cspm_=' + encodeURIComponent(cookie_val) + ';path=/;' + '';
}
return;
}
} catch (err) {
return;
}
setTimeout(f5_cspm.wait_perf_data, 100);
return;
},
go: function () {
var chunk = window.document.cookie.split(/s*;s*/);
for (var i = 0; i < chunk.length; ++i) {
var pair = chunk[i].split(/s*=s*/);
if (pair[0] == 'f5_cspm' && pair[1] == '1234') {
var d = new Date();
d.setTime(d.getTime() - 1000);
window.document.cookie = 'f5_cspm=;expires=' + d.toUTCString() + ';path=/;' + ';';
setTimeout(f5_cspm.wait_perf_data, 100);
}
}
}
};
f5_cspm.go();
}());
</script>
The reasoning why this is injected is described here: https://my.f5.com/manage/s/article/K13849
After the page loads I would like to use another script or even angular component and remove the <script id=f5_cspm”> and also stop the recurrent call for f5_cspm.wait_perf_data
.
I was able to remove the script, but I dont know how to reach the recurent method.
When I try to find it using window.f5_cspm
it returns undefined.
import { Injectable, Renderer2, RendererFactory2} from '@angular/core';
@Injectable({
providedIn: 'root' // This makes the service available globally in the app
})
export class MyService {
private renderer: Renderer2;
constructor( private rendererFactory: RendererFactory2) {
this.renderer = rendererFactory.createRenderer(null, null);
this.removef5()
}
private removef5() {
console.log('removef5 ');
const scriptTag = document.getElementById("f5_cspm");
if (scriptTag) {
console.log("script will be removed: " + scriptTag);
this.renderer.removeChild(scriptTag.parentElement, scriptTag); // Removes the script from the DOM
}
console.log('window.f5_cspm ' + window.f5_cspm); // prints undefined
}
}