qq15725 / modern-screenshot

📸 Quickly generate image from DOM node using HTML5 canvas and SVG
https://www.toolpkg.com/image/html-to-image
MIT License
457 stars 32 forks source link

Capacitor Support #60

Closed aeharding closed 7 months ago

aeharding commented 7 months ago

Hello!

I am wondering if you would be willing to accept a PR to add support for Capacitor's native HTTP fetch (https://capacitorjs.com/docs/apis/http#request).

The reason for this feature is because CapacitorHttp uses native device APIs and can completely bypass CORS.

In terms of changes to modern-screenshot, it would basically involve adding an option called fetchFn. You can see this on my fork, here:

https://github.com/aeharding/modern-screenshot/commit/d48ce73b181830faf3d586bc080bee2690781bee#diff-2123f97b7bf9480a61717c843425e483e8d97819592e8c04e4e149eb65b451e8R72

fetchFn can either return the data URL string, or return false to allow modern-screenshot to attempt fetch normally. This is useful because certain URLs (such as relative and insecure URLs) Capacitor cannot handle.

The implementation changes are available here:

https://github.com/aeharding/modern-screenshot/commit/d48ce73b181830faf3d586bc080bee2690781bee#diff-eeed782a266dc1fc529c811c9b7104828cfc608f349a191cab030dba2b5bc5f5

(please ignore includeStyleProperties, that's a separate feature of my fork.)

Anyways, let me know if you would be willing to support this and I would like to make a PR! 🚀

qq15725 commented 7 months ago

Welcome PR 🚀