{"record":{"id":"459059cb24ab906d","repo":"toeverything/AFFiNE","slug":"css-cannot-be-applied-when-printing-pdf-this-may","errorCode":null,"errorMessage":"css cannot be applied when printing pdf, this may be because of CORS policy from its domain.","messagePattern":"css cannot be applied when printing pdf, this may be because of CORS policy from its domain\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"blocksuite/affine/shared/src/utils/print-to-pdf.ts","lineNumber":124,"sourceCode":"                color: #000 !important;\n                -webkit-text-fill-color: #000 !important;\n              }\n              :root {\n                --affine-note-shadow-box: none !important;\n                --affine-note-shadow-sticker: none !important;\n              }\n            }</style></head><body></body></html>`);\n\n      // copy all styles to iframe\n      for (const element of document.styleSheets) {\n        try {\n          for (const cssRule of element.cssRules) {\n            const target = doc.styleSheets[0];\n            target.insertRule(cssRule.cssText, target.cssRules.length);\n          }\n        } catch (e) {\n          if (element.href) {\n            console.warn(\n              'css cannot be applied when printing pdf, this may be because of CORS policy from its domain.',\n              element.href\n            );\n          } else {\n            reject(e);\n          }\n        }\n      }\n\n      // Recursive function to find all canvases, including those in shadow roots\n      const findAllCanvases = (root: Node): HTMLCanvasElement[] => {\n        const canvases: HTMLCanvasElement[] = [];\n        const traverse = (node: Node) => {\n          if (node instanceof HTMLCanvasElement) {\n            canvases.push(node);\n          }\n          if (node instanceof HTMLElement || node instanceof ShadowRoot) {\n            node.childNodes.forEach(traverse);","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/blocksuite/affine/shared/src/utils/print-to-pdf.ts#L106-L142","documentation":"Warning logged in `printToPdf` when copying document stylesheets into the print iframe throws — typically a DOMException from reading `element.cssRules` of a cross-origin stylesheet blocked by CORS. Some print CSS may be missing so the PDF may render without those styles, but printing continues with the styles that could be copied.","triggerScenarios":"Triggered during print-to-PDF when reading cssRules of a cross-origin stylesheet throws a SecurityError, so that stylesheet's rules cannot be copied into the print iframe.","commonSituations":"Occurs when printing a page that loads CSS from another domain without CORS headers. The printed output may miss some styles; serve the stylesheet same-origin or with CORS enabled.","solutions":["Serve the stylesheet from the same origin or with CORS headers.","Inline critical CSS before printing."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}