()
| 192 | }; |
| 193 | |
| 194 | const scanPopup = () => { |
| 195 | if (popupWindow.closed) { |
| 196 | debugNativePdf(session, "popup window closed"); |
| 197 | cleanup(); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | const popupDoc = popupWindow.document; |
| 202 | const popupBody = popupDoc.body; |
| 203 | if (!popupBody) { |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | const printRoots = Array.from(popupDoc.querySelectorAll<HTMLElement>(".print")); |
| 208 | const fileEmbedCount = popupDoc.querySelectorAll(".file-embed").length; |
| 209 | const signature = `print:${printRoots.length}|embed:${fileEmbedCount}`; |
| 210 | if (session.lastPopupScanSignature !== signature) { |
| 211 | session.lastPopupScanSignature = signature; |
| 212 | debugNativePdf(session, "popup scan state changed", { |
| 213 | printRoots: printRoots.length, |
| 214 | fileEmbeds: fileEmbedCount, |
| 215 | url: popupWindow.location.href, |
| 216 | }); |
| 217 | } |
| 218 | |
| 219 | if (printRoots.length > 0) { |
| 220 | for (const root of printRoots) { |
| 221 | void replacePopupCodeEmbeds(root, plugin, session.sourceFile.path); |
| 222 | } |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | if (popupBody.querySelector(".file-embed")) { |
| 227 | void replacePopupCodeEmbeds(popupBody, plugin, session.sourceFile.path); |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | try { |
| 232 | debugNativePdf(session, "attached popup observer"); |
no test coverage detected