mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
[PM-5976] Safari Browser SSO Initialization Race Condition Attempted Fix 3 (#7800)
* [PM-5976] Safari Browser SSO Initialization Race Condition Attempted Fix 3 * [PM-5976] Safari Browser SSO Initialization Race Condition Attempted Fix 3 * [PM-5976] Removing usage of pinging system and keeping reworked top-level registration of window message listener events * [PM-5976] Pulling the implementation of the static content script delcaration for the content-message-handler file to the top of the list of content_scripts * [PM-5976] Pulling the implementation of the static content script delcaration for the content-message-handler file to the top of the list of content_scripts * [PM-5976] Removing the useCapture value within the window message event listener
This commit is contained in:
@@ -8,9 +8,9 @@ window.addEventListener("load", () => {
|
||||
const lastpass = getQsParam("lp");
|
||||
|
||||
if (lastpass === "1") {
|
||||
initiateBrowserSsoIfDocumentReady(code, state, true);
|
||||
initiateBrowserSso(code, state, true);
|
||||
} else if (state != null && state.includes(":clientId=browser")) {
|
||||
initiateBrowserSsoIfDocumentReady(code, state, false);
|
||||
initiateBrowserSso(code, state, false);
|
||||
} else {
|
||||
window.location.href = window.location.origin + "/#/sso?code=" + code + "&state=" + state;
|
||||
// Match any characters between "_returnUri='" and the next "'"
|
||||
@@ -23,33 +23,6 @@ window.addEventListener("load", () => {
|
||||
}
|
||||
});
|
||||
|
||||
function initiateBrowserSsoIfDocumentReady(code: string, state: string, lastpass: boolean) {
|
||||
const MAX_ATTEMPTS = 200;
|
||||
const TIMEOUT_MS = 50;
|
||||
let attempts = 0;
|
||||
|
||||
const pingInterval = setInterval(() => {
|
||||
if (attempts >= MAX_ATTEMPTS) {
|
||||
clearInterval(pingInterval);
|
||||
throw new Error("Failed to initiate browser SSO");
|
||||
}
|
||||
|
||||
attempts++;
|
||||
window.postMessage({ command: "checkIfReadyForAuthResult" }, "*");
|
||||
}, TIMEOUT_MS);
|
||||
|
||||
const handleWindowMessage = (event: MessageEvent) => {
|
||||
if (event.source === window && event.data?.command === "readyToReceiveAuthResult") {
|
||||
clearInterval(pingInterval);
|
||||
window.removeEventListener("message", handleWindowMessage);
|
||||
|
||||
initiateBrowserSso(code, state, lastpass);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("message", handleWindowMessage);
|
||||
}
|
||||
|
||||
function initiateBrowserSso(code: string, state: string, lastpass: boolean) {
|
||||
window.postMessage({ command: "authResult", code: code, state: state, lastpass: lastpass }, "*");
|
||||
const handOffMessage = ("; " + document.cookie)
|
||||
|
||||
Reference in New Issue
Block a user