Skip to content

Instantly share code, notes, and snippets.

@technikhil314
Last active April 24, 2024 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technikhil314/d4e3ec4b448abb16e2c7d2297e7b386f to your computer and use it in GitHub Desktop.
Save technikhil314/d4e3ec4b448abb16e2c7d2297e7b386f to your computer and use it in GitHub Desktop.
Trick to use secondary gmail secondary account as default in PWA on desktop

Issue

  1. Open gmail.com
  2. switch to secondary accuont in gmail
  3. install a Gmail as PWA on desktop as a seperate window
    • make sure the PWA has secondaary account opened in PWA window
  4. Quit the PWA and open it again
  5. Obeserve that
    • the primary account is opened in PWA always no matter how many times you quit and reopen
    • also you cant switch the account in PWA to secondary account
    • if you try to switch to the secondary account then it is opened in browser and not in PWA

Actual result

  1. The PWA URL always points to primary account

Expected result

  1. The the url should point to secondary account

Solution

To solve this problem please follow the steps below

  1. Run the following script in browser before installing PWA.
  • Change the startUrl to appropriate google app viz chat/gmail/calendar and the index to proper account
const startUrl = 'https://mail.google.com/chat/u/1/#chat/home';

const unsanitizedHtmlPolicy = trustedTypes.createPolicy('unsanitizedHtml', {
  createHTML: (htmlString) => htmlString,
});

document.head
  .querySelector(':first-child')
  .insertAdjacentHTML(
    'beforebegin',
    unsanitizedHtmlPolicy.createHTML(
      `<link rel="manifest" href='data:application/manifest+json,{"start_url":"${startUrl}"}' />`,
    ),
  );
  1. Now install it as PWA.
  2. Quit and start the PWA again to verify that the PWA points to correct account.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment