OfficeDev / microsoft-teams-library-js

JavaScript library for use by Microsoft Teams apps
https://docs.microsoft.com/microsoftteams/platform/
Other
427 stars 195 forks source link

"Initialization Failed. No Parent window found." in desktop app #2533

Open mfsysadmin opened 1 day ago

mfsysadmin commented 1 day ago

I have the following code from Microsoft Learn:

microsoftTeams.app.initialize().then(() => {
    getClientSideToken()
    .then((token) => {
        console.log(token);
    })
    .catch((error) => {
        console.log(error);
}).catch((error) => {
    console.log(error);
});
function getClientSideToken() {
    return new Promise((resolve, reject) => {
        microsoftTeams.authentication.getAuthToken().then((result) => {
            resolve(result);
        }).catch((error) => {
            reject("Error getting token: " + error);
        });
    });
}

Unfortunately on windows desktop app I get the following error: Error: Initialization Failed. No Parent window found.

Also in web app I have this error: Error: SDK initialization timed out.

microsoft-github-policy-service[bot] commented 1 day ago

Hi mfsysadmin! Thank you for bringing this issue to our attention. We will investigate and if we require further information we will reach out in one business day. Please use this link to escalate if you don't get replies.

Best regards, Teams Platform

KangxuanYe commented 1 day ago

Hi @mfsysadmin, thank you for reaching with the piece of code regarding of initialization on your app. Could you please follow the documentation in our wiki to turn on client logging and then share ALL of logs here so that we can have more detail to investigate what is exactly going on with your app and provide guidance for you?

Also, could you please elaborate more on which host platform (i.e. Teams web, Teams desktop) you are trying to make your app run on and what version of Teams-JS library you are using?

mfsysadmin commented 15 hours ago

Hi @KangxuanYe, in the webapp I have the following log messages:

teamsJs:app teamsjs is being used from https://cdn.jsdelivr.net/npm/@microsoft/teams-js@2.28.0/dist/MicrosoftTeams.min.js. Today, teamsjs can only be used from a single script or you may see undefined behavior. This log line is used to help detect cases where teamsjs is loaded multiple times -- it is always written. The presence of the log itself does not indicate a multi-load situation, but multiples of these log lines will. If you would like to use teamjs from more than one script at the same time, please open an issue at https://github.com/OfficeDev/microsoft-teams-library-js/issues +0ms
teamsJs:communication:sendMessageToParentHelper Message 0 information: Object { actionName: "initialize", args: (3) […] } +0ms
Sending message 0 to parent via postMessage +0ms [common.js:113:9](webpack://microsoftTeams/node_modules/.pnpm/debug@4.3.5/node_modules/debug/src/common.js)
teamsJs:validateOrigin isValidOriginsFromCDN call failed to validate origin: *.www.office.com +0ms
teamsJs:validateOrigin validOrigins fetch call to CDN failed with error: Error: Valid Origins List Is Invalid. Defaulting to fallback list +1ms

I use teams.microsoft.com, I don't know why it tries *.www.office.com Also I don't really understand the last message since it makes a request to https://res.cdn.office.net/teams-js/validDomains/json/validDomains.json

On Teams web I have the "Error: SDK initialization timed out." message, while in the desktop app I have "Error: Initialization Failed. No Parent window found.".

JE-Development commented 15 hours ago

Hello, I also have this issue. It suddenly appeared with no code changed. (Windows Desktop Version) I am using Teams Tab App. There I pasted my URL of my Vue.js project. app.ts:56 Uncaught (in promise) Error: SDK initialization timed out. at un (app.ts:56:7) at e3.initialize (app.ts:774:12) at Proxy.created (SelectPage.vue:59:24) at callWithErrorHandling (runtime-core.esm-bundler.js:199:33) at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:206:17) at callHook (runtime-core.esm-bundler.js:3498:3) at applyOptions (runtime-core.esm-bundler.js:3416:5) at finishComponentSetup (runtime-core.esm-bundler.js:7878:7) at setupStatefulComponent (runtime-core.esm-bundler.js:7801:5) at setupComponent (runtime-core.esm-bundler.js:7729:36)

KangxuanYe commented 9 hours ago

Hello, I also have this issue. It suddenly appeared with no code changed. (Windows Desktop Version) I am using Teams Tab App. There I pasted my URL of my Vue.js project. app.ts:56 Uncaught (in promise) Error: SDK initialization timed out. at un (app.ts:56:7) at e3.initialize (app.ts:774:12) at Proxy.created (SelectPage.vue:59:24) at callWithErrorHandling (runtime-core.esm-bundler.js:199:33) at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:206:17) at callHook (runtime-core.esm-bundler.js:3498:3) at applyOptions (runtime-core.esm-bundler.js:3416:5) at finishComponentSetup (runtime-core.esm-bundler.js:7878:7) at setupStatefulComponent (runtime-core.esm-bundler.js:7801:5) at setupComponent (runtime-core.esm-bundler.js:7729:36)

Hi @JE-Development , could you please create another ticket for us and then following the step that I mentioned above to send logs to us in the new ticket you created? In this way, your thread will not be messed up and we can help you better. Thanks.

jadahiya-MSFT commented 7 hours ago

Hi @mfsysadmin I'll be looking into this error for you, a few questions I have is that you mentioned that you are using teams.microsoft.com, is it correct for me to assume that you are trying to run your application in the Teams Web App environment?

Another question I have is how are you currently importing the TeamsJS library and if you downgraded your version from 2.28.0 to 2.26.0 do you see the same behavior?

Now to answer your question about why you are seeing the validOrigins fetch call failure. It appears that *.www.office.com is causing an issue in your environment leading to the CDN failure you are seeing. I am investigating why this is the case since *.www.office.com is in that CDN list that you've retrieved. That being said, it looks like it should still be defaulting back to a local list where teams.microsoft.com is being validated. Is there anymore to the logs or does it end at the validOrigins failure?