I have created a Trusted Web Activity. In order to hide some html content i have modified "startUrl": "/?utm_source=trusted-web-activity". I check for this query param and i save it in sessionStorage ( i dont use localStorage because it is shared with all tabs). Based on the existence of this params i display or hide some divs :
if(sessionStorage.getItem('activity')) {
document.getElementById( 'mobile_navigation' ).style.display = 'block'; }
Everything is working as is expected. The only problem is that if i keep the app in background for a while and i open it the page is reloaded and all the rules dont work anymore. I have even tried to populate a field and to get it from here.
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
trustewdweb = urlParams.get('utm_source');
let fields = document.getElementById("fields");
if (trustewdweb === 'trusted-web-activity'){
fields.value = trustewdweb;}
if(!sessionStorage.getItem('activity')) {
populateStorage();
} else {
populateField();
}
function populateStorage() {
sessionStorage.setItem('activity', document.getElementById('fields').value);
populateField();
}
function populateField() {
var currentQuery = sessionStorage.getItem('activity');
document.getElementById('fields').value = currentQuery ;
}
if(sessionStorage.getItem('activity')) {
How can i avoid this behaviour? It is related to cache?