0

I am using chrome.identity.launchWebAuthFlow to get a token from the MS graph API in ReactJS with TS.

If the extension popup closes for whatever reason, the auth window launched by chrome.identity remains open - I do not want this behaviour.

As well as this, for some reason the close event between the auth window and the extension popup seem to be linked - when I close the auth window the extension closes too, which also stops any further code from running.

How do I stop this happening? I suspect the issues arise from the same problem.


Updates:

  1. Moved the API call and launchWebAuthFlow into a persistent service worker
  2. Changed my async/await calls so that it must wait before closing the extension

I'm considering creating as issue on the chromium bug report website? I'm really not sure what's causing this.

Joe Moore
  • 2,031
  • 2
  • 8
  • 29
  • Before suggesting [this thread](https://stackoverflow.com/questions/3950981/closing-popup-window-created-by-google-chrome-extension?rq=2), it is outdated as well as not relevant to React. – Joe Moore Apr 08 '23 at 17:49

1 Answers1

1

It is hard to say what could be causing the first issue of the auth window not closing, without seeing your code.

Are you handling the errors on the extension window?

It is important to note that if there is an error in the extension window, it may not be immediately apparent, and it may prevent the auth window from closing. You need to handle it in the parent window like below:

chrome.identity.launchWebAuthFlow({
  url: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
  interactive: true,
}, (redirectUrl) => {
  if (chrome.runtime.lastError || !redirectUrl) {
    // Handle error
  } else {
    // Handle successful authentication
  }
});