single-file-frames.js 23 KB

1
  1. !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).singlefile={})}(this,function(e){"use strict";const t="single-file-load-image",s="single-file-image-loaded",o="_singleFile_fontFaces",n="_singleFile_worklets",i=globalThis.CustomEvent,r=globalThis.document,a=globalThis.Document,l=globalThis.JSON,d=globalThis.MutationObserver;let c,u;function m(){r instanceof a&&(r.addEventListener("single-file-new-font-face",e=>{const t=e.detail,s=Object.assign({},t);delete s.src,c.set(l.stringify(s),t)}),r.addEventListener("single-file-delete-font",e=>{const t=e.detail,s=Object.assign({},t);delete s.src,c.delete(l.stringify(s))}),r.addEventListener("single-file-clear-fonts",()=>c=new Map),r.addEventListener("single-file-new-worklet",e=>{const t=e.detail;u.set(t.moduleURL,t)}))}c=globalThis.window[o]?globalThis.window[o]:globalThis.window[o]=new Map,u=globalThis.window[n]?globalThis.window[n]:globalThis.window[n]=new Map,m(),new d(m).observe(r,{childList:!0});const h="[\\x20\\t\\r\\n\\f]",g=new RegExp("\\\\([\\da-f]{1,6}"+h+"?|("+h+")|.)","ig");const f="single-file-",p="__frameTree__::",b=f+"on-before-capture",E=f+"on-after-capture",T=f+"request-get-adopted-stylesheets",y=f+"response-get-adopted-stylesheets",w=f+"unregister-request-get-adopted-stylesheets",I="data-"+f+"removed-content",v="data-"+f+"hidden-content",A="data-"+f+"kept-content",S="data-"+f+"hidden-frame",R="data-"+f+"preserved-space-element",_="data-"+f+"shadow-root-element",M="data-"+f+"win-id",P="data-"+f+"image",N="data-"+f+"poster",C="data-"+f+"video",F="data-"+f+"canvas",L="data-"+f+"movable-style",x="data-"+f+"input-value",k="data-"+f+"input-checked",q="data-"+f+"lazy-loaded-src",U="data-"+f+"stylesheet",D="data-"+f+"disabled-noscript",O="data-"+f+"invalid-element",V="data-"+f+"async-script",W="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",H=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],z=["SCRIPT","NOSCRIPT","META","LINK","TEMPLATE"],B=/^'(.*?)'$/,j=/^"(.*?)"$/,Y={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},G="single-file-ui-element",Z="data:,",J=globalThis.JSON,K=globalThis.CustomEvent,$=globalThis.URL;function X(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],markedElements:[]},i=new Map,r){if(s.childNodes){Array.from(s.childNodes).filter(t=>t instanceof e.HTMLElement||t instanceof e.SVGElement||t instanceof globalThis.HTMLElement||t instanceof globalThis.SVGElement).forEach(s=>{let a,l,d;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(d=re(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(l=(r||s.closest("html > head"))&&H.includes(s.tagName.toUpperCase())||s.closest("details"),l||(a=r||oe(s,d),a&&!z.includes(s.tagName.toUpperCase())&&(s.setAttribute(v,""),n.markedElements.push(s)))),!a)){if(o.compressHTML&&d){const e=d.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(R,""),n.markedElements.push(s))}o.removeUnusedFonts&&(ee(d,o,n.usedFonts),ee(re(e,s,":first-letter"),o,n.usedFonts),ee(re(e,s,":before"),o,n.usedFonts),ee(re(e,s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,i,r){const a=s.tagName&&s.tagName.toUpperCase();if("CANVAS"==a)try{n.canvases.push({dataURI:s.toDataURL("image/png",""),backgroundColor:r.getPropertyValue("background-color")}),s.setAttribute(F,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==a){const t={currentSrc:i?Z:o.loadDeferredImages&&s.getAttribute(q)||s.currentSrc};if(n.images.push(t),s.setAttribute(P,n.images.length-1),n.markedElements.push(s),s.removeAttribute(q),r=r||re(e,s)){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const i=null==t.getAttribute("style");if(s=s||re(e,t)){let e,r,a,l,d,c,u,m,h=!1;if("content-box"==s.getPropertyValue("box-sizing")){const e=t.style.getPropertyValue("box-sizing"),s=t.style.getPropertyPriority("box-sizing"),o=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),h=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=ie("padding-left",s),r=ie("padding-right",s),a=ie("padding-top",s),l=ie("padding-bottom",s),h?(d=ie("border-left-width",s),c=ie("border-right-width",s),u=ie("border-top-width",s),m=ie("border-bottom-width",s)):d=c=u=m=0,o=Math.max(0,t.clientWidth-e-r-d-c),n=Math.max(0,t.clientHeight-a-l-u-m),i&&t.removeAttribute("style")}}return{pxWidth:o,pxHeight:n}}(e,s,r);const o=r.getPropertyValue("box-shadow"),n=r.getPropertyValue("background-image");o&&"none"!=o||n&&"none"!=n||!(t.size.pxWidth>1||t.size.pxHeight>1)||(t.replaceable=!0,t.backgroundColor=r.getPropertyValue("background-color"),t.objectFit=r.getPropertyValue("object-fit"),t.boxSizing=r.getPropertyValue("box-sizing"),t.objectPosition=r.getPropertyValue("object-position"))}}if("VIDEO"==a){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=re(e,s.parentNode);n.videos.push({positionParent:t&&t.getPropertyValue("position"),src:o,size:{pxWidth:s.clientWidth,pxHeight:s.clientHeight},currentTime:s.currentTime}),s.setAttribute(C,n.videos.length-1)}if(!s.getAttribute("poster")){const e=t.createElement("canvas"),o=e.getContext("2d");e.width=s.clientWidth,e.height=s.clientHeight;try{o.drawImage(s,0,0,e.width,e.height),n.posters.push(e.toDataURL("image/png","")),s.setAttribute(N,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==a&&i&&o.removeHiddenElements&&(s.setAttribute(S,""),n.markedElements.push(s));"INPUT"==a&&("password"!=s.type&&(s.setAttribute(x,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(k,s.checked),n.markedElements.push(s)));"TEXTAREA"==a&&(s.setAttribute(x,s.value),n.markedElements.push(s));"SELECT"==a&&s.querySelectorAll("option").forEach(e=>{e.selected&&(e.setAttribute(x,""),n.markedElements.push(e))});"SCRIPT"==a&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(V,""),n.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,o,n,a,d);const c=!(s instanceof e.SVGElement||s instanceof globalThis.SVGElement)&&te(s);if(c&&!s.classList.contains(G)&&"single-file-infobar"!=s.tagName.toLowerCase()){const r={};s.setAttribute(_,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(r);try{if(c.adoptedStyleSheets)if(c.adoptedStyleSheets.length)r.adoptedStyleSheets=Q(c.adoptedStyleSheets,i);else if(void 0===c.adoptedStyleSheets.length){const e=e=>r.adoptedStyleSheets=e.detail.adoptedStyleSheets;c.addEventListener(y,e),c.dispatchEvent(new K(T,{bubbles:!0})),r.adoptedStyleSheets||s.dispatchEvent(new K(T,{bubbles:!0})),c.removeEventListener(y,e)}}catch(e){}X(e,t,c,o,n,i,a),r.content=c.innerHTML,r.mode=c.mode,r.delegateFocus=c.delegatesFocus,r.clonable=c.clonable,r.serializable=c.serializable;try{c.adoptedStyleSheets&&void 0===c.adoptedStyleSheets.length&&c.dispatchEvent(new K(w,{bubbles:!0}))}catch(e){}}X(e,t,s,o,n,i,a),!o.autoSaveExternalSave&&o.removeHiddenElements&&r&&(l||""==s.getAttribute(A)?s.parentElement&&(s.parentElement.setAttribute(A,""),n.markedElements.push(s.parentElement)):a&&(s.setAttribute(I,""),n.markedElements.push(s)))})}return n}function Q(e,t=new Map){if(e){const s=[];for(const o of Array.from(e))if(t.has(o))s.push(t.get(o));else{let e="";if(o&&o.cssRules)for(const t of o.cssRules)e+=t.cssText+"\n";t.set(o,e),s.push(e)}return s}return[]}function ee(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach(n=>{if(n=se(n),!t.loadedFonts||t.loadedFonts.find(e=>se(e.family)==n&&e.style==o)){const t=(i=e.getPropertyValue("font-weight"),Y[i.toLowerCase().trim()]||i),r=e.getPropertyValue("font-variant")||"normal",a=[n,t,o,r];s.set(J.stringify(a),[n,t,o,r])}var i})}}function te(e){const t=globalThis.chrome;if(e.openOrClosedShadowRoot)return e.openOrClosedShadowRoot;if(!(t&&t.dom&&t.dom.openOrClosedShadowRoot))return e.shadowRoot;try{return t.dom.openOrClosedShadowRoot(e)}catch(t){return e.shadowRoot}}function se(e=""){return function(e){e=e.match(B)?e.replace(B,"$1"):e.replace(j,"$1");return e.trim()}((t=e.trim(),t.replace(g,(e,t,s)=>{const o="0x"+t-65536;return o!=o||s?t:o<0?String.fromCharCode(o+65536):String.fromCharCode(o>>10|55296,1023&o|56320)}))).toLowerCase();var t}function oe(e,t){let s=!1;if(t){const o=t.getPropertyValue("display"),n=t.getPropertyValue("opacity"),i=t.getPropertyValue("visibility");if(s="none"==o,!s&&("0"==n||"hidden"==i)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function ne(e){if(e){const t=[];return e.querySelectorAll("style").forEach((s,o)=>{try{if(!s.sheet.disabled){const n=e.createElement("style");n.textContent=s.textContent,e.body.appendChild(n);const i=n.sheet;n.remove();const r=Array.from(i.cssRules).map(e=>e.cssText).join("\n"),a=Array.from(s.sheet.cssRules).map(e=>e.cssText).join("\n");i&&r==a||(s.setAttribute(U,o),t[o]=Array.from(s.sheet.cssRules).map(e=>e.cssText).join("\n"))}}catch(e){}}),t}}function ie(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function re(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const ae={LAZY_SRC_ATTRIBUTE_NAME:q,SINGLE_FILE_UI_ELEMENT_CLASS:G},le="attributes",de=globalThis.browser,ce=globalThis.document,ue=globalThis.MutationObserver,me=new Map;let he;async function ge(e){if(ce.documentElement){me.clear();const o=ce.body?Math.max(ce.body.scrollHeight,ce.documentElement.scrollHeight):ce.documentElement.scrollHeight,n=ce.body?Math.max(ce.body.scrollWidth,ce.documentElement.scrollWidth):ce.documentElement.scrollWidth;if(o>globalThis.innerHeight||n>globalThis.innerWidth){const a=Math.max(o-1.5*globalThis.innerHeight,0),l=Math.max(n-1.5*globalThis.innerWidth,0);if(globalThis.scrollY<a||globalThis.scrollX<l)return function(e){return he=0,new Promise(async o=>{let n;const a=new Set,l=new ue(async t=>{if((t=t.filter(e=>e.type==le)).length){t.filter(e=>{if("src"==e.attributeName&&(e.target.setAttribute(ae.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",c)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(ae.SINGLE_FILE_UI_ELEMENT_CLASS)}).length&&(n=!0,await pe(l,e,h),a.size||await fe(l,e,h))}});async function d(t){await Ee("idleTimeout",async()=>{n?he<10&&(he++,ye("idleTimeout"),await d(Math.max(500,t/2))):(ye("loadTimeout"),ye("maxTimeout"),be(l,e,h))},t,e.loadDeferredImagesNativeTimeout)}function c(e){const t=e.target;t.removeAttribute(ae.LAZY_SRC_ATTRIBUTE_NAME),t.removeEventListener("load",c)}async function u(t){n=!0,await pe(l,e,h),await fe(l,e,h),t.detail&&a.add(t.detail)}async function m(t){await pe(l,e,h),await fe(l,e,h),a.delete(t.detail),a.size||await fe(l,e,h)}function h(e){l.disconnect(),ce.removeEventListener(t,u),ce.removeEventListener(s,m),o(e)}await d(2*e.loadDeferredImagesMaxIdleTime),await pe(l,e,h),l.observe(ce,{subtree:!0,childList:!0,attributes:!0}),ce.addEventListener(t,u),ce.addEventListener(s,m),function(e){e.loadDeferredImagesBlockCookies&&r.dispatchEvent(new i("single-file-block-cookies-start")),e.loadDeferredImagesBlockStorage&&r.dispatchEvent(new i("single-file-block-storage-start")),e.loadDeferredImagesDispatchScrollEvent&&r.dispatchEvent(new i("single-file-dispatch-scroll-event-start")),e.loadDeferredImagesKeepZoomLevel?r.dispatchEvent(new i("single-file-load-deferred-images-keep-zoom-level-start")):r.dispatchEvent(new i("single-file-load-deferred-images-start"))}(e)})}(e)}}}async function fe(e,t,s){await Ee("loadTimeout",()=>be(e,t,s),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function pe(e,t,s){await Ee("maxTimeout",async()=>{await ye("loadTimeout"),await be(e,t,s)},10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function be(e,t,s){await ye("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&r.dispatchEvent(new i("single-file-block-cookies-end")),e.loadDeferredImagesBlockStorage&&r.dispatchEvent(new i("single-file-block-storage-end")),e.loadDeferredImagesDispatchScrollEvent&&r.dispatchEvent(new i("single-file-dispatch-scroll-event-end")),e.loadDeferredImagesKeepZoomLevel?r.dispatchEvent(new i("single-file-load-deferred-images-keep-zoom-level-end")):r.dispatchEvent(new i("single-file-load-deferred-images-end"))}(t),await Ee("endTimeout",async()=>{await ye("maxTimeout"),s()},t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function Ee(e,t,s,o){if(de&&de.runtime&&de.runtime.sendMessage&&!o){if(!me.get(e)||!me.get(e).pending){const o={callback:t,pending:!0};me.set(e,o);try{await de.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){Te(e,t,s)}o.pending=!1}}else Te(e,t,s)}function Te(e,t,s){const o=me.get(e);o&&globalThis.clearTimeout(o),me.set(e,t),globalThis.setTimeout(t,s)}async function ye(e){if(de&&de.runtime&&de.runtime.sendMessage)try{await de.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){we(e)}else we(e)}function we(e){const t=me.get(e);me.delete(e),t&&globalThis.clearTimeout(t)}de&&de.runtime&&de.runtime.onMessage&&de.runtime.onMessage.addListener&&de.runtime.onMessage.addListener(e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=me.get(e.type);if(t){me.delete(e.type);try{t.callback()}catch(t){we(e.type)}}}});const Ie={ON_BEFORE_CAPTURE_EVENT_NAME:b,ON_AFTER_CAPTURE_EVENT_NAME:E,WIN_ID_ATTRIBUTE_NAME:M,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:"_singleFile_waitForUserScript",preProcessDoc:function(e,t,s){e.querySelectorAll("noscript:not(["+D+"])").forEach(e=>{e.setAttribute(D,e.textContent),e.textContent=""}),function(e){e.querySelectorAll("meta[http-equiv=refresh]").forEach(e=>{e.removeAttribute("http-equiv"),e.setAttribute("disabled-http-equiv","refresh")})}(e),e.head&&e.head.querySelectorAll(W).forEach(e=>e.hidden=!0),e.querySelectorAll("svg foreignObject").forEach(e=>{const t=e.querySelectorAll("html > head > "+W+", html > body > "+W);t.length&&(Array.from(e.childNodes).forEach(e=>e.remove()),t.forEach(t=>e.appendChild(t)))});const o=new Map;let n;t&&e.documentElement?(e.querySelectorAll("button button, a a").forEach(t=>{const s=e.createElement("template");s.setAttribute(O,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)}),n=X(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach(e=>{const s=re(t,e);s&&oe(e,s)&&(e.setAttribute(L,""),n.markedElements.push(e))})):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]};let i="";if(e.referrer)try{i=new $("/",new $(e.referrer).origin).href}catch(e){}return{canvases:n.canvases,fonts:Array.from(c.values()),worklets:Array.from(u.values()),stylesheets:ne(e),images:n.images,posters:n.posters,videos:n.videos,usedFonts:Array.from(n.usedFonts.values()),shadowRoots:n.shadowRoots,referrer:i,markedElements:n.markedElements,invalidElements:o,scrollPosition:{x:t.scrollX,y:t.scrollY},adoptedStyleSheets:Q(e.adoptedStyleSheets)}},serialize:function(e){const t=e.doctype;let s="";return t&&(s="<!DOCTYPE "+t.nodeName,t.publicId?(s+=' PUBLIC "'+t.publicId+'"',t.systemId&&(s+=' "'+t.systemId+'"')):t.systemId&&(s+=' SYSTEM "'+t.systemId+'"'),t.internalSubset&&(s+=" ["+t.internalSubset+"]"),s+="> "),s+e.documentElement.outerHTML},postProcessDoc:function(e,t,s){if(e.querySelectorAll("["+D+"]").forEach(e=>{e.textContent=e.getAttribute(D),e.removeAttribute(D)}),e.querySelectorAll("meta[disabled-http-equiv]").forEach(e=>{e.setAttribute("http-equiv",e.getAttribute("disabled-http-equiv")),e.removeAttribute("disabled-http-equiv")}),e.head&&e.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach(e=>e.removeAttribute("hidden")),!t){const s=[I,S,v,R,P,N,C,F,x,k,_,U,V];t=e.querySelectorAll(s.map(e=>"["+e+"]").join(","))}t.forEach(e=>{e.removeAttribute(I),e.removeAttribute(v),e.removeAttribute(A),e.removeAttribute(S),e.removeAttribute(R),e.removeAttribute(P),e.removeAttribute(N),e.removeAttribute(C),e.removeAttribute(F),e.removeAttribute(x),e.removeAttribute(k),e.removeAttribute(_),e.removeAttribute(U),e.removeAttribute(V),e.removeAttribute(L)}),s&&s.forEach((e,t)=>e.replaceWith(t))},getShadowRoot:te},ve='iframe, frame, object[type="text/html"][data]',Ae="singlefile.frameTree.initRequest",Se="singlefile.frameTree.ackInitRequest",Re="singlefile.frameTree.cleanupRequest",_e="singlefile.frameTree.initResponse",Me=5e3,Pe=".",Ne=globalThis.window==globalThis.top,Ce=globalThis.browser,Fe=globalThis.top,Le=globalThis.MessageChannel,xe=globalThis.document,ke=globalThis.JSON,qe=globalThis.MutationObserver,Ue=globalThis.DOMParser;let De,Oe=globalThis.sessions;function Ve(){globalThis.addEventListener("message",async e=>{if("string"==typeof e.data&&e.data.startsWith(p)){e.preventDefault(),e.stopPropagation();const t=ke.parse(e.data.substring(15));if(t.method==Ae)e.source&&Ke(e.source,{method:Se,windowId:t.windowId,sessionId:t.sessionId}),Ne||(globalThis.stop(),t.options.loadDeferredImages&&ge(t.options),await He(t));else if(t.method==Se)Ye("requestTimeouts",t.sessionId,t.windowId),Ge(t.sessionId,t.windowId);else if(t.method==Re)ze(t);else if(t.method==_e&&Oe.get(t.sessionId)){e.ports[0].onmessage=e=>Be(e.data)}}},!0)}function We(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function He(e){const t=e.sessionId,s=globalThis[Ie.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ne||(De=globalThis.frameId=e.windowId),je(xe,e.options,De,t),Ne||(e.options.userScriptEnabled&&s&&await s(Ie.ON_BEFORE_CAPTURE_EVENT_NAME,e.options),Je({frames:[$e(xe,globalThis,De,e.options,e.scrolling)],sessionId:t,requestedFrameId:xe.documentElement.dataset.requestedFrameId&&De}),e.options.userScriptEnabled&&s&&await s(Ie.ON_AFTER_CAPTURE_EVENT_NAME,e.options),delete xe.documentElement.dataset.requestedFrameId)}function ze(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;Ze(Xe(xe),e.windowId,t)}}function Be(e){e.frames.forEach(t=>Ye("responseTimeouts",e.sessionId,t.windowId));const t=Oe.get(e.sessionId);if(t){e.requestedFrameId&&(t.requestedFrameId=e.requestedFrameId),e.frames.forEach(e=>{let s=t.frames.find(t=>e.windowId==t.windowId);s||(s={windowId:e.windowId},t.frames.push(s)),s.processed||(s.content=e.content,s.baseURI=e.baseURI,s.title=e.title,s.url=e.url,s.canvases=e.canvases,s.fonts=e.fonts,s.worklets=e.worklets,s.stylesheets=e.stylesheets,s.images=e.images,s.posters=e.posters,s.videos=e.videos,s.usedFonts=e.usedFonts,s.shadowRoots=e.shadowRoots,s.processed=e.processed,s.scrollPosition=e.scrollPosition,s.scrolling=e.scrolling,s.adoptedStyleSheets=e.adoptedStyleSheets)});t.frames.filter(e=>!e.processed).length||(t.frames=t.frames.sort((e,t)=>t.windowId.split(Pe).length-e.windowId.split(Pe).length),t.resolve&&(t.requestedFrameId&&t.frames.forEach(e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)}),t.resolve(t.frames)))}}function je(e,t,s,o){const n=Xe(e);!function(e,t,s,o,n){const i=[];let r;Oe.get(n)?r=Oe.get(n).requestTimeouts:(r={},Oe.set(n,{requestTimeouts:r}));t.forEach((e,t)=>{const s=o+Pe+t;e.setAttribute(Ie.WIN_ID_ATTRIBUTE_NAME,s),i.push({windowId:s})}),Je({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach((e,t)=>{const i=o+Pe+t;try{Ke(e.contentWindow,{method:Ae,windowId:i,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}r[i]=globalThis.setTimeout(()=>Je({frames:[{windowId:i,processed:!0}],sessionId:n}),Me)}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o),n.length&&function(e,t,s,o,n){const i=[];t.forEach((e,t)=>{const r=o+Pe+t;let a,l;try{a=e.contentDocument,l=e.contentWindow,l.stop()}catch(e){}const d=e.getAttribute("srcdoc");if(!a&&d){a=(new Ue).parseFromString(d,"text/html"),l=globalThis}if(a)try{Ye("requestTimeouts",n,r),je(a,s,r,n),i.push($e(a,l,r,s,e.scrolling))}catch(e){i.push({windowId:r,processed:!0})}}),Je({frames:i,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function Ye(e,t,s){const o=Oe.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function Ge(e,t){const s=Oe.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout(()=>Je({frames:[{windowId:t,processed:!0}],sessionId:e}),1e4))}function Ze(e,t,s){e.forEach((e,o)=>{const n=t+Pe+o;e.removeAttribute(Ie.WIN_ID_ATTRIBUTE_NAME);try{Ke(e.contentWindow,{method:Re,windowId:n,sessionId:s})}catch(e){}}),e.forEach((e,o)=>{const n=t+Pe+o;let i;try{i=e.contentDocument}catch(e){}if(i)try{Ze(Xe(i),n,s)}catch(e){}})}function Je(e){e.method=_e;try{Fe.singlefile.processors.frameTree.initResponse(e)}catch(t){Ke(Fe,e,!0)}}function Ke(e,t,s){if(e==Fe&&Ce&&Ce.runtime&&Ce.runtime.sendMessage)Ce.runtime.sendMessage(t);else if(s){const s=new Le;e.postMessage(p+ke.stringify({method:t.method,sessionId:t.sessionId}),"*",[s.port2]),s.port1.postMessage(t)}else e.postMessage(p+ke.stringify(t),"*")}function $e(e,t,s,o,n){const i=Ie.preProcessDoc(e,t,o),r=Ie.serialize(e);Ie.postProcessDoc(e,i.markedElements,i.invalidElements);return{windowId:s,content:r,baseURI:e.baseURI.split("#")[0],url:e.documentURI,title:e.title,canvases:i.canvases,fonts:i.fonts,worklets:i.worklets,stylesheets:i.stylesheets,images:i.images,posters:i.posters,videos:i.videos,usedFonts:i.usedFonts,shadowRoots:i.shadowRoots,scrollPosition:i.scrollPosition,scrolling:n,adoptedStyleSheets:i.adoptedStyleSheets,processed:!0}}function Xe(e){let t=Array.from(e.querySelectorAll(ve));return e.querySelectorAll("*").forEach(e=>{const s=Ie.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(ve)))}),t}Oe||(Oe=globalThis.sessions=new Map),Ne&&(De="0",Ce&&Ce.runtime&&Ce.runtime.onMessage&&Ce.runtime.onMessage.addListener&&Ce.runtime.onMessage.addListener(e=>e.method==_e?(Be(e),Promise.resolve({})):e.method==Se?(Ye("requestTimeouts",e.sessionId,e.windowId),Ge(e.sessionId,e.windowId),Promise.resolve({})):void 0)),Ve(),new qe(Ve).observe(xe,{childList:!0}),e.TIMEOUT_INIT_REQUEST_MESSAGE=Me,e.cleanup=function(e){Oe.delete(e),ze({windowId:De,sessionId:e})},e.getAsync=function(e){const t=We();return e=ke.parse(ke.stringify(e)),new Promise(s=>{Oe.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),He({windowId:De,sessionId:t,options:e})})},e.getSync=function(e){const t=We();e=ke.parse(ke.stringify(e)),Oe.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[Ie.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ne||(De=globalThis.frameId=e.windowId);je(xe,e.options,De,t),Ne||(e.options.userScriptEnabled&&s&&s(Ie.ON_BEFORE_CAPTURE_EVENT_NAME,e.options),Je({frames:[$e(xe,globalThis,De,e.options,e.scrolling)],sessionId:t,requestedFrameId:xe.documentElement.dataset.requestedFrameId&&De}),e.options.userScriptEnabled&&s&&s(Ie.ON_AFTER_CAPTURE_EVENT_NAME,e.options),delete xe.documentElement.dataset.requestedFrameId)}({windowId:De,sessionId:t,options:e});const s=Oe.get(t).frames;return s.sessionId=t,s},e.initResponse=Be});