0

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?

7even
  • 23
  • 5
  • My guess here is: The tab with the Trusted Web Activity is getting killed and when the user returns to the application is restarted. But at this point the session storage is gone. Do you have a small reproduction app? It may be worth filing a bug on https://crbug.com/ – andreban Nov 20 '20 at 14:55
  • There are 2 scenarios. 1)If the app stays in backround some hours, indeed application is restarted when i open it from background (splash screen again and default url). 2)If the app stays some hours when reopen it from background no splash screen just i can see that page is refreshed and my input field is populated with "trusted-web-activity" but at manual refresh dissapear, also on back i have the field populated. The only problem is that rules dont work, both scenarios. Dont have now an app as i tested so many ways. May i ask you related to FCM token or i must create new question? – 7even Nov 20 '20 at 15:32

0 Answers0