chore(pdfjs): set proper target origin when posting messages

This commit is contained in:
Elian Doran 2025-12-31 16:37:51 +02:00
parent 7182d32d9c
commit bf3a2b768e
No known key found for this signature in database
5 changed files with 19 additions and 19 deletions

View File

@ -50,7 +50,7 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
iframeRef.current?.contentWindow?.postMessage({
type: "trilium-scroll-to-heading",
headingId: heading.id
}, "*");
}, window.location.origin);
}
});
} else {
@ -81,13 +81,13 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
iframeRef.current?.contentWindow?.postMessage({
type: "trilium-scroll-to-page",
pageNumber: page
}, "*");
}, window.location.origin);
},
requestThumbnail: (page: number) => {
iframeRef.current?.contentWindow?.postMessage({
type: "trilium-request-thumbnail",
pageNumber: page
}, "*");
}, window.location.origin);
}
});
}
@ -119,7 +119,7 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
iframeRef.current?.contentWindow?.postMessage({
type: "trilium-download-attachment",
filename
}, "*");
}, window.location.origin);
}
});
}
@ -132,7 +132,7 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
type: "trilium-toggle-layer",
layerId,
visible
}, "*");
}, window.location.origin);
}
});
}

View File

@ -24,7 +24,7 @@ async function extractAndSendAttachments() {
window.parent.postMessage({
type: "pdfjs-viewer-attachments",
attachments: []
}, "*");
}, window.location.origin);
return;
}
@ -42,13 +42,13 @@ async function extractAndSendAttachments() {
filename: att.filename,
size: att.size
}))
}, "*");
}, window.location.origin);
} catch (error) {
console.error("Error extracting attachments:", error);
window.parent.postMessage({
type: "pdfjs-viewer-attachments",
attachments: []
}, "*");
}, window.location.origin);
}
}

View File

@ -28,7 +28,7 @@ async function extractAndSendLayers() {
window.parent.postMessage({
type: "pdfjs-viewer-layers",
layers: []
}, "*");
}, window.location.origin);
return;
}
@ -38,7 +38,7 @@ async function extractAndSendLayers() {
window.parent.postMessage({
type: "pdfjs-viewer-layers",
layers: []
}, "*");
}, window.location.origin);
return;
}
@ -77,13 +77,13 @@ async function extractAndSendLayers() {
window.parent.postMessage({
type: "pdfjs-viewer-layers",
layers
}, "*");
}, window.location.origin);
} catch (error) {
console.error("Error extracting layers:", error);
window.parent.postMessage({
type: "pdfjs-viewer-layers",
layers: []
}, "*");
}, window.location.origin);
}
}

View File

@ -16,7 +16,7 @@ export function setupPdfPages() {
window.parent.postMessage({
type: "pdfjs-viewer-current-page",
currentPage: evt.pageNumber
}, "*");
}, window.location.origin);
});
// Listen for scroll-to-page requests
@ -43,7 +43,7 @@ function sendPageInfo() {
type: "pdfjs-viewer-page-info",
totalPages: app.pdfDocument.numPages,
currentPage: app.pdfViewer.currentPageNumber
}, "*");
}, window.location.origin);
}
async function generateThumbnail(pageNumber: number) {
@ -76,7 +76,7 @@ async function generateThumbnail(pageNumber: number) {
type: "pdfjs-viewer-thumbnail",
pageNumber,
dataUrl
}, "*");
}, window.location.origin);
} catch (error) {
console.error(`Error generating thumbnail for page ${pageNumber}:`, error);
}

View File

@ -11,7 +11,7 @@ export async function extractAndSendToc() {
window.parent.postMessage({
type: "pdfjs-viewer-toc",
data: null
}, "*");
}, window.location.origin);
return;
}
@ -26,12 +26,12 @@ export async function extractAndSendToc() {
window.parent.postMessage({
type: "pdfjs-viewer-toc",
data: toc
}, "*");
}, window.location.origin);
} catch (error) {
window.parent.postMessage({
type: "pdfjs-viewer-toc",
data: null
}, "*");
}, window.location.origin);
}
}
@ -163,7 +163,7 @@ export function setupActiveHeadingTracking() {
window.parent.postMessage({
type: "pdfjs-viewer-active-heading",
headingId: activeHeadingId
}, "*");
}, window.location.origin);
}
}