Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix bug with polyfill fetch #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Xuan-Yu-San
Copy link

No description provided.

@Xuan-Yu-San
Copy link
Author

@microsoft-github-policy-service agree

@Xuan-Yu-San
Copy link
Author

When using fetch-event-source in the webview of iOS or Android, it is important to note that the fetch method is not implemented as native code. Instead, it is a polyfill that provides functionality similar to the native fetch method. One specific difference is that the polyfill does not have a response with a body of type ReadableStream. Considering this limitation is therefore crucial in such cases.

@congjinruo
Copy link

your code may cause repeated fetch requests. I adjusted it.

export async function getBytes(response: Response, onChunk: (arr: Uint8Array) => void) {
    const reader = response.body?.getReader();
    if (reader) {
        let result;
        while (!(result = await reader.read()).done) {
            onChunk(result.value);
        }
    } else {
        onChunk(new Uint8Array(await response.arrayBuffer()));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants