The compression method 'CompressionStream' in the web front-end is not supported on iOS browser #6810

Closed
opened 2026-02-21 18:17:25 -05:00 by yindo · 1 comment
Owner

Originally created by @760485464 on GitHub (Nov 17, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.11.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

The compression method 'CompressionStream' in the web front-end is not supported on iOS

code in public/embed.js

    async function compressAndEncodeBase64(input) {
      const uint8Array = new TextEncoder().encode(input);
      const compressedStream = new Response(
          new Blob([uint8Array]).stream().pipeThrough(new CompressionStream('gzip'))
      ).arrayBuffer();
      const compressedUint8Array = new Uint8Array(await compressedStream);
      return btoa(String.fromCharCode(...compressedUint8Array));
    }

5401731900586_ pic

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @760485464 on GitHub (Nov 17, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.11.1 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce The compression method 'CompressionStream' in the web front-end is not supported on iOS code in public/embed.js ``` async function compressAndEncodeBase64(input) { const uint8Array = new TextEncoder().encode(input); const compressedStream = new Response( new Blob([uint8Array]).stream().pipeThrough(new CompressionStream('gzip')) ).arrayBuffer(); const compressedUint8Array = new Uint8Array(await compressedStream); return btoa(String.fromCharCode(...compressedUint8Array)); } ``` ![5401731900586_ pic](https://github.com/user-attachments/assets/05269a77-e045-4943-9961-7c4d1f3b6139) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:17:25 -05:00
yindo closed this issue 2026-02-21 18:17:25 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 17, 2024):

Hello @760485464! I'm here to help you with any bugs, questions, or contributions. Let's work together to address the issue you've encountered.

The CompressionStream API is indeed not supported on iOS browsers, which can cause issues with the compressAndEncodeBase64 function in the Dify web front-end. To handle this, you can implement a feature detection mechanism to check if CompressionStream is available and provide a fallback method for environments where it is not supported.

Here's a basic example of how you might modify the function to include a check for CompressionStream and use an alternative compression method if necessary:

async function compressAndEncodeBase64(input) {
  const uint8Array = new TextEncoder().encode(input);

  if ('CompressionStream' in window) {
    const compressedStream = new Response(
      new Blob([uint8Array]).stream().pipeThrough(new CompressionStream('gzip'))
    ).arrayBuffer();
    const compressedUint8Array = new Uint8Array(await compressedStream);
    return btoa(String.fromCharCode(...compressedUint8Array));
  } else {
    // Fallback method for environments without CompressionStream
    // Example: Use a library like pako for gzip compression
    const pako = await import('pako');
    const compressed = pako.gzip(uint8Array);
    return btoa(String.fromCharCode(...compressed));
  }
}

In this example, if CompressionStream is not available, the function uses the pako library to perform gzip compression. You would need to include the pako library in your project for this fallback to work. This approach ensures that your application remains functional across different browsers, including iOS.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 17, 2024): <!-- Greeting --> Hello @760485464! I'm here to help you with any bugs, questions, or contributions. Let's work together to address the issue you've encountered. <!-- Answer --> The `CompressionStream` API is indeed not supported on iOS browsers, which can cause issues with the `compressAndEncodeBase64` function in the Dify web front-end. To handle this, you can implement a feature detection mechanism to check if `CompressionStream` is available and provide a fallback method for environments where it is not supported. Here's a basic example of how you might modify the function to include a check for `CompressionStream` and use an alternative compression method if necessary: ```javascript async function compressAndEncodeBase64(input) { const uint8Array = new TextEncoder().encode(input); if ('CompressionStream' in window) { const compressedStream = new Response( new Blob([uint8Array]).stream().pipeThrough(new CompressionStream('gzip')) ).arrayBuffer(); const compressedUint8Array = new Uint8Array(await compressedStream); return btoa(String.fromCharCode(...compressedUint8Array)); } else { // Fallback method for environments without CompressionStream // Example: Use a library like pako for gzip compression const pako = await import('pako'); const compressed = pako.gzip(uint8Array); return btoa(String.fromCharCode(...compressed)); } } ``` In this example, if `CompressionStream` is not available, the function uses the `pako` library to perform gzip compression. You would need to include the `pako` library in your project for this fallback to work. This approach ensures that your application remains functional across different browsers, including iOS. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6810