This pull request is an attempt to resolve the issue of IOS not loading images #442
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
IOS (Safari) devices requests credentials to be sent across on all fetch request. That makes all requests that doesn't have the pre-defined credentials to fail. However, when the credential is set as true with the fetchRequestInit interface, Images are loaded well, but the fonts is blocked. This is because fonts.gstatic.com makes use of wildcard as their Access-Control-Allow-Origin, which doesn't go at same time with when the credentials is set to 'include'. Thus the proposal of creating a different interface "fetchFontRequestInit" which will be used on embed-webfonts.ts. This also adds to the flexibility to the library
Motivation and Context
I encountered this issue while working on a project that requires me convert html to images. I checked through the communities, but I couldn't seeing any solution that worked for me. So I decided to check through it. That's how I came to this solution.
Bellow are some of the common open issues.
To Fix this Problem,
/**
*
*the second parameter of window.fetch (Promise fetch(input[, init]))
*/
fetchFontRequestInit?: RequestInit
...
return fetchAsDataURL<[string, string]>(
url,
options.fetchFontRequestInit,
({ result }) => {
cssText = cssText.replace(loc,
url(${result})
)return [loc, result]
},
)
...
Types of changes
Self Check before Merge