From 2ad247b7176bdd853027b7c36b8f356ad36d2cbe Mon Sep 17 00:00:00 2001 From: Allen Gong Date: Wed, 14 Aug 2019 10:54:44 -0700 Subject: [PATCH 1/8] ag - Refactor isIEOrEdge to separate static methods This will allow for finer control over handling of each browser agent --- src/helpers/utilities.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/helpers/utilities.ts b/src/helpers/utilities.ts index eca8f7a..cbddcbd 100644 --- a/src/helpers/utilities.ts +++ b/src/helpers/utilities.ts @@ -184,11 +184,25 @@ export class Utilities { return Utilities.host !== HostType.WEB; } + /** + * Utility to check if the browser is IE11. + */ + static get isIE() { + return /Trident\//gi.test(window.navigator.userAgent); + } + + /** + * Utility to check if the browser is Edge. + */ + static get isEdge() { + return /Edge\//gi.test(window.navigator.userAgent); + } + /** * Utility to check if the browser is IE11 or Edge. */ static get isIEOrEdge() { - return /Edge\/|Trident\//gi.test(window.navigator.userAgent); + return Utilities.isIE || Utilities.isEdge; } /** From db1cabd3affa4743f2fc6110b5279b43045019c6 Mon Sep 17 00:00:00 2001 From: Allen Gong Date: Wed, 14 Aug 2019 10:55:22 -0700 Subject: [PATCH 2/8] ag - Force Edge environments to be handled as a non add-in --- src/helpers/utilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/utilities.ts b/src/helpers/utilities.ts index cbddcbd..95158c2 100644 --- a/src/helpers/utilities.ts +++ b/src/helpers/utilities.ts @@ -181,7 +181,7 @@ export class Utilities { * Utility to check if the code is running inside of an add-in. */ static get isAddin() { - return Utilities.host !== HostType.WEB; + return Utilities.host !== HostType.WEB && !Utilities.isEdge; } /** From 2df85d037ebe509d68caa50fe58426709c6da8b7 Mon Sep 17 00:00:00 2001 From: Allen Gong Date: Wed, 14 Aug 2019 11:09:23 -0700 Subject: [PATCH 3/8] ag - Open authentication dialog on Edge using displayDialogAsync We will continue to use localStorage as a means of communication between windows --- src/helpers/dialog.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/helpers/dialog.ts b/src/helpers/dialog.ts index 9ffa5c5..91c41d2 100644 --- a/src/helpers/dialog.ts +++ b/src/helpers/dialog.ts @@ -74,6 +74,9 @@ export class Dialog { else if (Utilities.isAddin) { this._result = this._addinDialog(); } + else if (Utilities.isEdge) { + this._result = this._edgeDialog(); + } else { this._result = this._webDialog(); } @@ -124,7 +127,7 @@ export class Dialog { try { const options = 'width=' + this.size.width + ',height=' + this.size.height + this._windowFeatures; window.open(this.url, this.url, options); - if (Utilities.isIEOrEdge) { + if (Utilities.isIE) { this._pollLocalStorageForToken(resolve, reject); } else { @@ -143,6 +146,19 @@ export class Dialog { }); } + private _edgeDialog(): Promise { + return new Promise((resolve, reject) => { + Office.context.ui.displayDialogAsync(this.url, { width: this.size.width$, height: this.size.height$ }, (result: Office.AsyncResult) => { + if (result.status === Office.AsyncResultStatus.Failed) { + reject(new DialogError(result.error.message, result.error)); + } + else { + this._pollLocalStorageForToken(resolve, reject); + } + }); + }); + } + private _pollLocalStorageForToken(resolve: (value: T) => void, reject: (reason: DialogError) => void) { localStorage.removeItem(Dialog.key); const POLL_INTERVAL = 400; From 3540ec1ed6816e411855ab70b07a79a6dface3c9 Mon Sep 17 00:00:00 2001 From: Allen Gong Date: Wed, 17 Mar 2021 18:45:59 -0700 Subject: [PATCH 4/8] Ensure dialog is closed after successfully retrieving token --- src/helpers/dialog.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/helpers/dialog.ts b/src/helpers/dialog.ts index 91c41d2..0e4b848 100644 --- a/src/helpers/dialog.ts +++ b/src/helpers/dialog.ts @@ -153,7 +153,16 @@ export class Dialog { reject(new DialogError(result.error.message, result.error)); } else { - this._pollLocalStorageForToken(resolve, reject); + const dialog = result.value as Office.DialogHandler; + const onToken = token => { + if (dialog) { + dialog.close(); + } + + return resolve(token); + }; + + this._pollLocalStorageForToken(onToken, reject); } }); }); From c3e0087ae8d6a9cd68588598d6e79a4de5b958c3 Mon Sep 17 00:00:00 2001 From: Allen Gong Date: Wed, 17 Mar 2021 18:50:39 -0700 Subject: [PATCH 5/8] 1.0.3 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0d4301f..4d11fea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@microsoft/office-js-helpers", - "version": "1.0.1", + "version": "1.0.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f8b6cc7..89b6ae8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@microsoft/office-js-helpers", "description": "A collection of helpers to simplify development of Office Add-ins & Microsoft Teams Tabs", - "version": "1.0.2", + "version": "1.0.3", "repository": { "type": "git", "url": "git+https://github.com/OfficeDev/office-js-helpers.git" From 7ae712a70b523d5c56ef326fd6614645ef44b9b6 Mon Sep 17 00:00:00 2001 From: Allen Gong Date: Thu, 25 Mar 2021 14:38:19 -0700 Subject: [PATCH 6/8] Send token via messageParent for Edge dialogs --- src/helpers/dialog.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/dialog.ts b/src/helpers/dialog.ts index 0e4b848..37dba0c 100644 --- a/src/helpers/dialog.ts +++ b/src/helpers/dialog.ts @@ -210,11 +210,11 @@ export class Dialog { microsoftTeams.initialize(); microsoftTeams.authentication.notifySuccess(JSON.stringify({ parse, value })); } - else if (Utilities.isAddin) { + else if (Utilities.isAddin || Utilities.isEdge) { Office.context.ui.messageParent(JSON.stringify({ parse, value })); } else { - if (Utilities.isIEOrEdge) { + if (Utilities.isIE) { localStorage.setItem(Dialog.key, JSON.stringify({ parse, value })); } else if (window.opener) { From 952bfe1bf656daa519443849e315421e68db7a06 Mon Sep 17 00:00:00 2001 From: Allen Gong Date: Thu, 25 Mar 2021 14:39:28 -0700 Subject: [PATCH 7/8] Listen for dialog messages for Edge The handler for Edge environments used to poll for localStorage, but due to issues relating to Edge WebView2 rollout, localStorage is no longer shared between the dialog prompt and add-in pane. This change essentially reverts the original change from 2019 that updated the handling to rely on localStorage. The reason we are doing this is because: 1. The authentication flow is broken until MS resolves this bug: https://github.com/OfficeDev/office-js/issues/1741 2. messageParent has always been the preferred communication medium as noted in the DialogApi documentation: https://docs.microsoft.com/en-us/office/dev/add-ins/develop/dialog-api-in-office-add-ins 3. There was a finding that the dialog needs to be opened with a URL that matches the opener. With this change, messageParent now appears to be working correctly. --- src/helpers/dialog.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/helpers/dialog.ts b/src/helpers/dialog.ts index 37dba0c..242f5f7 100644 --- a/src/helpers/dialog.ts +++ b/src/helpers/dialog.ts @@ -154,15 +154,17 @@ export class Dialog { } else { const dialog = result.value as Office.DialogHandler; - const onToken = token => { - if (dialog) { - dialog.close(); - } - return resolve(token); - }; + dialog.addEventHandler(Office.EventType.DialogMessageReceived, args => { + let result = this._safeParse(args.message) as T; + resolve(result); + dialog.close(); + }); - this._pollLocalStorageForToken(onToken, reject); + dialog.addEventHandler(Office.EventType.DialogEventReceived, args => { + reject(new DialogError(args.message, args.error)); + dialog.close(); + }); } }); }); From f46480fbadd54365fbe0ec657082f5b362776fad Mon Sep 17 00:00:00 2001 From: Allen Gong Date: Thu, 25 Mar 2021 16:16:34 -0700 Subject: [PATCH 8/8] 2.0.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4d11fea..c915d4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@microsoft/office-js-helpers", - "version": "1.0.3", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 89b6ae8..63e6efe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@microsoft/office-js-helpers", "description": "A collection of helpers to simplify development of Office Add-ins & Microsoft Teams Tabs", - "version": "1.0.3", + "version": "2.0.0", "repository": { "type": "git", "url": "git+https://github.com/OfficeDev/office-js-helpers.git"