From d80cfbcd03319bea116aee992c3304e6a4efd866 Mon Sep 17 00:00:00 2001 From: Michel Schmit Date: Sat, 21 Oct 2023 13:07:58 -0400 Subject: [PATCH 1/2] add filters on useCredentials queries --- src/dom-to-image-more.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/dom-to-image-more.js b/src/dom-to-image-more.js index a72167b3..a4fe8f73 100644 --- a/src/dom-to-image-more.js +++ b/src/dom-to-image-more.js @@ -16,6 +16,8 @@ cacheBust: false, // Use (existing) authentication credentials for external URIs (CORS requests) useCredentials: false, + // Use (existing) authentication credentials for external URIs (CORS requests) on some filtered requests only + useCredentialsFilters: [], // Default resolve timeout httpTimeout: 30000, // Style computation cache tag rules (options are strict, relaxed) @@ -278,6 +280,12 @@ domtoimage.impl.options.useCredentials = options.useCredentials; } + if (typeof options.useCredentialsFilters === 'undefined') { + domtoimage.impl.options.useCredentialsFilters = defaultOptions.useCredentialsFilters; + } else { + domtoimage.impl.options.useCredentialsFilters = options.useCredentialsFilters; + } + if (typeof options.httpTimeout === 'undefined') { domtoimage.impl.options.httpTimeout = defaultOptions.httpTimeout; } else { @@ -800,6 +808,13 @@ request.ontimeout = timeout; request.responseType = 'blob'; request.timeout = httpTimeout; + + if (domtoimage.impl.options.useCredentialsFilters.length > 0) { + domtoimage.impl.options.useCredentials = + domtoimage.impl.options.useCredentialsFilters.filter( + (credentialsFilter) => url.search(credentialsFilter) >= 0 + ).length > 0; + } if (domtoimage.impl.options.useCredentials) { request.withCredentials = true; } @@ -1371,8 +1386,8 @@ const docType = document.doctype; const docTypeDeclaration = docType ? `' + docType.publicId + )} ${escapeHTML(docType.systemId)}`.trim() + '>' : ''; // Create a hidden sandbox