You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/configuration.md
+59Lines changed: 59 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ These are all of the available configuration options.
7
7
| allowTaint | `false` | Whether to allow cross-origin images to taint the canvas
8
8
| backgroundColor | `#ffffff` | Canvas background color, if none is specified in DOM. Set `null` for transparent
9
9
| canvas | `null` | Existing `canvas` element to use as a base for drawing on
10
+
| customIsSameOrigin | `null` | Custom function to determine if an image URL is same-origin. Accepts two parameters: `(src: string, oldFn: (src: string) => boolean) => boolean | Promise<boolean>` where `src` is the image URL and `oldFn` is the default same-origin check function.
10
11
| foreignObjectRendering | `false` | Whether to use ForeignObject rendering if the browser supports it
11
12
| imageTimeout | `15000` | Timeout for loading an image (in milliseconds). Set to `0` to disable timeout.
12
13
| ignoreElements | `(element) => false` | Predicate function which removes the matching elements from the render.
@@ -26,3 +27,61 @@ These are all of the available configuration options.
26
27
| windowHeight | `Window.innerHeight` | Window height to use when rendering `Element`, which may affect things like Media queries
27
28
28
29
If you wish to exclude certain `Element`s from getting rendered, you can add a `data-html2canvas-ignore` attribute to those elements and html2canvas-pro will exclude them from the rendering.
30
+
31
+
### Custom isSameOrigin usage
32
+
33
+
The `customIsSameOrigin` option allows you to override the default same-origin detection logic, which is particularly useful in the following scenarios:
34
+
35
+
1.**Handling redirects**: When an image URL from your domain redirects to an external domain
36
+
2.**CDN configurations**: When your content is served from multiple domains or CDNs
37
+
3.**Force CORS mode**: When you want to force all images to use CORS regardless of origin
38
+
39
+
#### Basic usage
40
+
41
+
```typescript
42
+
html2canvas(element, {
43
+
useCORS: true,
44
+
customIsSameOrigin: (src, oldFn) => {
45
+
// If old logic think it's not same origin, certainly it's not
46
+
if (!oldFn(src)) {
47
+
returnfalse;
48
+
}
49
+
// Otherwise, we need to check if it's a redirect url
50
+
const targetUrl =newURL(src);
51
+
const pathname =targetUrl.pathname;
52
+
// You can replace it with any logic you want. Including but not limited to: using regular expressions, using asynchronous validation logic
53
+
// Here we simply suppose your biz url starts with /some-redirect-prefix and treat it as a redirect url just for example
0 commit comments