Skip to content

Commit bba7c03

Browse files
committed
Remove DOMPurify sanitization from website fetcher and fallback to document title
- sometimes a parsed website doesn't show its title in symbol but domain. while inspecting source code of the website we can see <title> being filled. └── apps └── editor ├── package.json └── src ├── extension.ts └── views └── prompt ├── backend │ ├── message-handlers │ │ ├── handle-open-website.ts │ │ ├── handle-paste-url.ts │ │ └── index.ts │ ├── prompt-view-provider.ts │ └── utils │ ├── persistent-text-storage.ts │ ├── symbols │ │ ├── replace-symbols.ts │ │ └── website │ │ └── replace-website-symbol.ts │ └── website-fetcher.ts ├── frontend │ ├── Main │ │ ├── Main.tsx │ │ └── MainView │ │ └── MainView.tsx │ ├── Prompt.tsx │ └── hooks │ └── use-prompt │ └── use-prompt.ts └── types └── messages.ts
1 parent f64e212 commit bba7c03

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

‎apps/editor/src/views/prompt/backend/utils/website-fetcher.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import axios from 'axios'
22
import { JSDOM } from 'jsdom'
33
import * as dns from 'dns/promises'
44
import { Readability, isProbablyReaderable } from '@mozilla/readability'
5-
import createDOMPurify from 'dompurify'
65
import TurndownServiceJoplin from '@joplin/turndown'
76
import * as turndownPluginGfm from '@joplin/turndown-plugin-gfm'
87
import type TurndownService from 'turndown'
@@ -127,10 +126,7 @@ export const fetch_website = async (
127126

128127
if (response.status === 200 && typeof response.data === 'string') {
129128
const html = response.data
130-
const window = new JSDOM('').window
131-
const DOMPurify = createDOMPurify(window as any)
132-
const clean_html = DOMPurify.sanitize(html)
133-
const dom = new JSDOM(clean_html, { url })
129+
const dom = new JSDOM(html, { url })
134130
const doc = dom.window.document
135131

136132
doc.querySelectorAll('pre').forEach((pre) => {
@@ -183,7 +179,7 @@ export const fetch_website = async (
183179
content = remove_markdown_images(content)
184180

185181
if (content && content.trim().length > 0) {
186-
return { content, title: article.title || '' }
182+
return { content, title: article.title || doc.title || '' }
187183
}
188184
}
189185
}

0 commit comments

Comments
 (0)