Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

clipper: remove invalid element attributes for screenshot clips Signed-off-by: 01zulfi <[email protected]>

01zulfi5d1775151d6c
diff --git a/packages/clipper/src/domtoimage.ts b/packages/clipper/src/domtoimage.ts
index 185af3100..c8d1ad365 100644
--- a/packages/clipper/src/domtoimage.ts
+++ b/packages/clipper/src/domtoimage.ts
@@ -138,6 +138,20 @@ function makeSvgDataUri(
) {
body.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
+ /**
+ * We're removing all attributes that contain non-word characters
+ * Sometimes a webpage could have invalid html and that causes attribute names to break
+ * HTML is resilient to this but SVG is not and will throw an error, so we remove these attributes altogether
+ */
+ for (const element of body.querySelectorAll("img, svg, video, iframe")) {
+ const attributes = element.getAttributeNames();
+ for (const attribute of attributes) {
+ if (attribute.match(/\W/)) {
+ element.removeAttribute(attribute);
+ }
+ }
+ }
+
const xhtml = new XMLSerializer().serializeToString(body);
const xstyles = Array.from(head.getElementsByTagName("style"))