Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.06k stars 1.19k forks source link

[ELECTRON JS] - ProxyPolicy is not supported in browser environment #30123

Closed Wolff51 closed 2 months ago

Wolff51 commented 3 months ago

Describe the bug Hey there. I'm trying to use @azure/storage-blob in my electron vue JS APP.

I have this test.js file working well when lauching "node test.js" command :

const { BlobServiceClient } = require("@azure/storage-blob");

const AZURE_STORAGE_CONNECTION_STRING =
  process.env.AZURE_STORAGE_CONNECTION_STRING;
const blobServiceClient = BlobServiceClient.fromConnectionString(
  AZURE_STORAGE_CONNECTION_STRING
);

async function listContainers() {
  const containers = blobServiceClient.listContainers();
  for await (const container of containers) {
    console.log(`Container name: ${container.name}`);
  }
}

listContainers().catch((error) =>
  console.error("Error listing containers:", error)
);

When trying to integrate and use it into my electron/vue app, i always have the following error : ProxyPolicy is not supported in browser environment.

I try many thing including using @azure/identity & InteractiveBrowserCredential, but nothing work for me.

If anyone can help me with this issue, i'll be gratefull.

github-actions[bot] commented 3 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

maorleger commented 3 months ago

Hey @Wolff51 - I'd love to give it a try and help out. I am not really an Electron expert but I do remember that these "other" environments (i.e. not Node.js and not a browser) can cause compatibility issues.

In order to help, could you share a minimal reproducible example that repros this issue? That will help get you the fastest response. Feel free to put something on GitHub and send me the link.

If you're unable to do so, you can share enough code that I can easily copy-paste it to my environment (I think I will need package.json and the source files similar to https://github.com/electron/electron-quick-start)

Thanks so much!

github-actions[bot] commented 3 months ago

Hi @Wolff51. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

mattporter74 commented 3 months ago

I am experiencing the same issue - hopefully this is helpful @maorleger

npm init electron-app@latest my-app -- --template=webpack-typescript
cd my-app
npm install
npm install @azure/storage-blob

open src/preload.ts and put this code in

import { BlockBlobClient } from "@azure/storage-blob";
const blockBlobClient = new BlockBlobClient("https://thisdoesntmatter.com");
const body = "hello world";
blockBlobClient.upload(body, body.length);

open src/index.ts add this to webPreferences

    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
    },

run it, and check the console npm start

jeremymeng commented 3 months ago

So it seems we added the proxyPolicy to the pipeline because isNode is true probably because of node integration is enabled, but still the browser version of the proxyPolicy is bundled and used.

There's a possible workaround if you are using the latest @azure/storage-blob version:

  (blockBlobClient as any).pipeline._corePipeline.removePolicy({ name: "proxyPolicy" });
mattporter74 commented 3 months ago

Problem is, the error happens in the constructor. so there is no way to modify the _corePipeline after the fact.

I am attempting to create a fully formed pipeline manually (with _corePipeline set) and then use it to construct the BlockBlobClient. No luck yet ;)

mattporter74 commented 3 months ago

i give up.. i just reverted to @azure/storage-blob 12.16.0 and ill run with that for now

Thanks for the time and attention guys!

maorleger commented 3 months ago

Hi @mattporter74 - appreciate your struggles here 😄 I was planning to try out your repro today as I'm juggling a few things.

I did go ahead and repro this. As you probably already know this is due to nodeIntegration flag - if you disable it you will of course be able to get things working; however, I totally understand that's not always possible.

Electron is... weird in nodeIntegration-land, and as you can see we've had many questions about it and all lead to nodeIntegration

Do you have to use nodeIntegration? I am not an electron expert so I am curious why you'd need this (doesn't seem like it's the default option)

mattporter74 commented 3 months ago

Thanks everyone. Unfortunately, i must have nodeIntegration ;( In my case, its because i am reading the local filesystem - and some additional out of the sandbox type functionality.

Note to future electron people that may run across this - use @azure/storage-blob 12.16.0!

github-actions[bot] commented 2 months ago

Hi @Wolff51, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!