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

Support more fine grained fetchRequestInit options #503

Open
wkelly1 opened this issue Feb 21, 2025 · 1 comment
Open

Support more fine grained fetchRequestInit options #503

wkelly1 opened this issue Feb 21, 2025 · 1 comment

Comments

@wkelly1
Copy link

wkelly1 commented Feb 21, 2025

The fetchRequestInit options available on the conversion functions are only available as a global option. The logic for this can be found here: https://github.com/bubkoo/html-to-image/blob/master/src/dataurl.ts#L86.

For the general case this is fine however there are cases where you need to set specific options per request. For example, if you have two images within the DOM nodes that you are converting, one that requires credentials but another that doesn't and has Access-control-Allow-Origin set to * then the conversion will fail due to CORS restrictions. There are likely other cases where this is important.

Expected Behaviour

The fetchRequestInit options should allow you to specify the options per resourceUrl which would give the user full control over how the request is handled.

Possible Solution

Te fetchRequestUrl should support the ability to be a function that takes the parameter resourceUrl and returns the RequestInit options.

e.g.

fetchRequestInit: RequestInit | (resourceUrl: string) => RequestInit

This would let the user then do:

fetchRequestInit: (resourceUrl) => {
  if (resourceUrl === "https://example.com/...") {
     return {
       credentials: "include"
     }
  }

  return {
    credentials: "omit"
  }
}

This would then also be backwards compatible without a breaking change.

@biiibooo
Copy link
Contributor

biiibooo bot commented Feb 21, 2025

👋 @wkelly1

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it.
To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

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

No branches or pull requests

1 participant