@@ -239,7 +239,8 @@ function operatorListHasDOMFilters({ fnArray, argsArray }) {
239239 * The default value is `false`.
240240 * @property {HTMLDocument } [ownerDocument] - Specify an explicit document
241241 * context to create elements with and to load resources, such as fonts,
242- * into. Defaults to the current document.
242+ * into. Defaults to the current document. Renderer-worker rendering is
243+ * disabled when this is set to a custom document.
243244 * @property {boolean } [disableRange] - Disable range request loading of PDF
244245 * files. When enabled, and if the server supports partial content requests,
245246 * then the PDF will be fetched in chunks. The default value is `false`.
@@ -377,10 +378,22 @@ function getDocument(src = {}) {
377378 const enableHWA = src . enableHWA === true ;
378379 const useWasm = src . useWasm !== false ;
379380 const pagesMapper = src . pagesMapper || new PagesMapper ( ) ;
381+ const styleElement =
382+ typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" )
383+ ? src . styleElement
384+ : null ;
385+ // Custom DOM contexts are main-thread only and cannot be transferred to
386+ // the renderer worker.
387+ const hasCustomOwnerDocument =
388+ src . ownerDocument !== undefined &&
389+ src . ownerDocument !== globalThis . document ;
390+ const hasCustomStyleElement = ! ! styleElement ;
380391 const disableWorkerRendering =
381392 src . disableWorkerRendering === true ||
382393 typeof Worker === "undefined" ||
383- typeof MessageChannel === "undefined" ;
394+ typeof MessageChannel === "undefined" ||
395+ hasCustomOwnerDocument ||
396+ hasCustomStyleElement ;
384397
385398 // Parameters whose default values depend on other parameters.
386399 const length = rangeTransport ? rangeTransport . length : ( src . length ?? NaN ) ;
@@ -403,13 +416,6 @@ function getDocument(src = {}) {
403416 isValidFetchUrl ( standardFontDataUrl , document . baseURI ) &&
404417 isValidFetchUrl ( wasmUrl , document . baseURI )
405418 ) ;
406-
407- // Parameters only intended for development/testing purposes.
408- const styleElement =
409- typeof PDFJSDev === "undefined" || PDFJSDev . test ( "TESTING" )
410- ? src . styleElement
411- : null ;
412-
413419 // Set the main-thread verbosity level.
414420 setVerbosityLevel ( verbosity ) ;
415421
@@ -3672,8 +3678,6 @@ class InternalRenderTask {
36723678 const { viewport, transform, background, dependencyTracker } = this . params ;
36733679
36743680 // TODO(Aditi): Should we disable worker rendering when pdfBug is enabled?
3675- const hasOperatorListChunk =
3676- this . operatorList . argsArray . length > 0 || this . operatorList . lastChunk ;
36773681
36783682 // Worker Rendering is disabled when canvas filters are present because
36793683 // OffscreenCanvas's OffscreenCanvasRenderingContext2D completely ignores
@@ -3684,7 +3688,7 @@ class InternalRenderTask {
36843688 this . _rendererHandler &&
36853689 this . _canvasContext === null &&
36863690 ! hasCanvasFilters &&
3687- hasOperatorListChunk ;
3691+ ! this . pageColors ;
36883692
36893693 // TODO(Aditi): Should we disable worker rendering when pdfBug is enabled?
36903694 if ( ! useWorkerRendering ) {
0 commit comments