microsoftgraph / microsoft-graph-toolkit

Authentication Providers and UI components for Microsoft Graph 🦒
https://docs.microsoft.com/graph/toolkit/overview
Other
945 stars 303 forks source link

[BUG] Electron Provider requires contextIsolation: false and should only expose the required apis #2599

Closed sonyafenge closed 8 months ago

sonyafenge commented 1 year ago

Describe the bug Follow instruction from https://learn.microsoft.com/en-us/graph/toolkit/get-started/build-an-electron-app to build an electron app. got the error as below:

[34796:0711/172014.532:ERROR:command_buffer_proxy_impl.cc(128)] ContextResult::kTransientFailure: Failed to send GpuControl.CreateCommandBuffer.
[13056:0711/172015.205:ERROR:CONSOLE(1)] "Uncaught (in promise) TypeError: Failed to fetch", source: devtools://devtools/bundled/panels/elements/elements.js (1)
[13056:0711/172015.392:ERROR:CONSOLE(1)] "Request Network.loadNetworkResource failed. {"code":-32602,"message":"Unsupported URL scheme"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1)
[13056:0711/172015.395:ERROR:CONSOLE(1)] "Request Network.loadNetworkResource failed. {"code":-32602,"message":"Unsupported URL scheme"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1)

To Reproduce Steps to reproduce the behavior:

  1. Go to page: https://learn.microsoft.com/en-us/graph/toolkit/get-started/build-an-electron-app
  2. Follow instruction to build an electron app
  3. after all steps, run "npm start"
  4. See error
    
    PS C:\Temp\electron-quick-start-typescript> npm start

electron-quick-start-typescript@1.0.0 start npm run webpack && electron dist/main.js

electron-quick-start-typescript@1.0.0 webpack webpack

asset renderer.js 3.28 MiB [compared for emit] (name: main) orphan modules 292 KiB [orphan] 160 modules runtime modules 937 bytes 4 modules modules by path ./node_modules/@microsoft/ 1.89 MiB 324 modules modules by path ./node_modules/@fluentui/web-components/ 226 KiB 89 modules modules by path ./node_modules/@lit/reactive-element/node/development/ 65.7 KiB 12 modules modules by path ./node_modules/lit-html/node/development/ 95 KiB 7 modules modules by path ./node_modules/lit/ 1010 bytes 5 modules modules by path ./node_modules/idb/build/esm/*.js 10.4 KiB ./node_modules/idb/build/esm/index.js 3.09 KiB [built] [code generated] ./node_modules/idb/build/esm/wrap-idb-value.js 7.32 KiB [built] [code generated] modules by path ./node_modules/@lit-labs/ssr-dom-shim/ 9.13 KiB ./node_modules/@lit-labs/ssr-dom-shim/index.js 4.92 KiB [built] [code generated] ./node_modules/@lit-labs/ssr-dom-shim/lib/element-internals.js 4.21 KiB [built] [code generated]

asset main.js 1.44 MiB [compared for emit] (name: main) orphan modules 40 KiB [orphan] 17 modules runtime modules 1.04 KiB 5 modules modules by path ./node_modules/ 1.2 MiB modules by path ./node_modules/@azure/ 554 KiB 58 modules modules by path ./node_modules/semver/ 60.1 KiB 44 modules modules by path ./node_modules/jsonwebtoken/ 22.4 KiB 12 modules modules by path ./node_modules/@microsoft/mgt-electron-provider/dist/Authenticator/.js 22 KiB 6 modules modules by path ./node_modules/uuid/dist/esm-node/.js 2.48 KiB 5 modules modules by path ./node_modules/jws/ 7.36 KiB 5 modules modules by path ./node_modules/ecdsa-sig-formatter/src/.js 5.34 KiB 2 modules modules by path ./node_modules/yallist/.js 8.42 KiB 2 modules

[34796:0711/172014.532:ERROR:command_buffer_proxy_impl.cc(128)] ContextResult::kTransientFailure: Failed to send GpuControl.CreateCommandBuffer. [13056:0711/172015.205:ERROR:CONSOLE(1)] "Uncaught (in promise) TypeError: Failed to fetch", source: devtools://devtools/bundled/panels/elements/elements.js (1) [13056:0711/172015.392:ERROR:CONSOLE(1)] "Request Network.loadNetworkResource failed. {"code":-32602,"message":"Unsupported URL scheme"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1) [13056:0711/172015.395:ERROR:CONSOLE(1)] "Request Network.loadNetworkResource failed. {"code":-32602,"message":"Unsupported URL scheme"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1)


**Expected behavior**
no error and page start successfully

**Environment (please complete the following information):**
 - OS:Windows 10 Enterprise
 - Browser: Microsoft Edge
ghost commented 1 year ago

Hello sonyafenge, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

gavinbarron commented 1 year ago

Thanks for raising this @sonyafenge

The fetch errors are from the open developer console and don't appear to be the cause of the issue. As a workaround you can use contextIsolation: false in the webPreference object when configuring the main window in main.ts.

We're looking into how we best update our electron provider to work as expected after the change to the contextIsolation defaults that came in electron 12.

gavinbarron commented 1 year ago

The path forward likely involves adding a function to be used in the preload script to register apis on the context bridge for use in the main and isolated worlds https://www.electronjs.org/docs/latest/api/context-bridge

musale commented 8 months ago

@sonyafenge there has been work done to address isolated context and preloading scripts here https://github.com/microsoftgraph/microsoft-graph-toolkit/pull/2914. Could you try it out from our preview @microsoft/mgt@next release?

microsoft-github-policy-service[bot] commented 8 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.