(rawUrl)
| 36 | * @returns {string} sanitized url |
| 37 | */ |
| 38 | export function sanitizeUrl (rawUrl) { |
| 39 | try { |
| 40 | const url = new URL(rawUrl) |
| 41 | if (url.protocol === 'http:' || url.protocol === 'https:') { |
| 42 | return url.toString() |
| 43 | } |
| 44 | |
| 45 | throw new Error('Invalid protocol') |
| 46 | } catch (error) { |
| 47 | return 'about:blank' |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // Check if URL is a PDF based on Content-Type header |
| 52 | export async function isPdfUrl (url) { |