From 2c57a4232cbee8b557b7b4da31b52db29515d276 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 1 Jan 2023 14:39:03 +0100 Subject: [PATCH] [api-minor] Improve the `useWorkerFetch` default value checks Given that the Fetch API only supports the http/https protocols, worker-thread fetching of CMaps and Standard-fonts may thus fail in certain cases. To improve the default behaviour we'll now also check that the `cMapUrl` and `standardFontDataUrl` options are appropriate, except in Firefox where this should always work. --- src/display/api.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 2dca8fb07..dc4800aef 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -47,6 +47,7 @@ import { DOMCMapReaderFactory, DOMStandardFontDataFactory, isDataScheme, + isValidFetchUrl, loadScript, PageViewport, RenderingCancelledException, @@ -363,8 +364,11 @@ function getDocument(src) { } if (typeof params.useWorkerFetch !== "boolean") { params.useWorkerFetch = - params.CMapReaderFactory === DOMCMapReaderFactory && - params.StandardFontDataFactory === DOMStandardFontDataFactory; + (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) || + (params.CMapReaderFactory === DOMCMapReaderFactory && + params.StandardFontDataFactory === DOMStandardFontDataFactory && + isValidFetchUrl(params.cMapUrl, document.baseURI) && + isValidFetchUrl(params.standardFontDataUrl, document.baseURI)); } if (typeof params.isEvalSupported !== "boolean") { params.isEvalSupported = true;