Search code examples
javascriptgoogle-apps-scriptgoogle-sheetsweb-applications

How to Prevent Browser from Adding User Parameter in URL Of Apps Script Based Web App?


I have a web app functioning from the last two years but after updating some features and adding a new page I starting getting an error that Page not found. When I looked further I got to know it is because of User Parameter in the URL which can be seen in screenshots '/u/1' is being added in my script URL Automatically as click on a link. I tried removing it manually but it doesn't help, I have tried several modes of deployment. And if I roll back to my older version it still works fine or if I log in only with a single account it works with the new version as well. So I wanted some light is possible to overcome this issue? I am just a part-time coder who can create something based on my needs so even after looking for the whole day I couldn't get it working so as of now I have rolled back to the old version.

Thanks in advance I am more than happy to share any more info required.

Screenshots attached with URL difference and error. Error with user param in URL

enter image description here


Solution

  • So I was able to find a workaround after roaming around in Google Forum as well they stated that it can not be solved since its intended behavior. so what I did was done some modification in my function which was being used to get script URL and added some desired string to overcome user specific error when logged in with multiple users.

    Here is the code

    function getScriptUrl() {
      var url = ScriptApp.getService().getUrl();
      var stringToBeChanged = 'macros/s';
      var newString = 'a/authentic.co.in/macros/s';
      url = url.replace(stringToBeChanged,newString);
      return url;
    }
    

    I hope this helps someone with a similar issue thank you for your support.