pdf 添加跨域功能 修复pdf 页码和高亮没启用bug

This commit is contained in:
高雄
2026-04-15 14:40:41 +08:00
parent 171762d676
commit ee2a27501b
2 changed files with 79 additions and 44 deletions

View File

@@ -23083,24 +23083,26 @@ initCom(PDFViewerApplication);
}
{
const HOSTED_VIEWER_ORIGINS = new Set(["null", "http://mozilla.github.io", "https://mozilla.github.io"]);
var validateFileURL = function (file) {
if (!file) {
return;
}
const viewerOrigin = URL.parse(window.location)?.origin || "null";
if (HOSTED_VIEWER_ORIGINS.has(viewerOrigin)) {
return;
}
const fileOrigin = URL.parse(file, window.location)?.origin;
if (fileOrigin === viewerOrigin) {
return;
}
const ex = new Error("file origin does not match viewer's");
PDFViewerApplication._documentError("pdfjs-loading-error", {
message: ex.message
});
throw ex;
};
var validateFileURL = function (file) {
if (!file) {
return;
}
const viewerOrigin = URL.parse(window.location)?.origin || "null";
if (HOSTED_VIEWER_ORIGINS.has(viewerOrigin)) {
return;
}
/* 注释掉跨域检查
const fileOrigin = URL.parse(file, window.location)?.origin;
if (fileOrigin === viewerOrigin) {
return;
}
const ex = new Error("file origin does not match viewer's");
PDFViewerApplication._documentError("pdfjs-loading-error", {
message: ex.message
});
throw ex;
*/
};
var onFileInputChange = function (evt) {
if (this.pdfViewer?.isInPresentationMode) {
return;