|
|
@@ -1599,7 +1599,8 @@ const processIframeLinks = async () => {
|
|
|
console.log('更新后的iframe元素:', updatedElement)
|
|
|
return {
|
|
|
...updatedElement,
|
|
|
- isDone: true
|
|
|
+ // type=73 的探测+抓取延迟到 BaseFrameElement 打开时执行(isDone!==true 才触发)
|
|
|
+ isDone: element.toolType === 73 ? (updatedElement.isDone ?? false) : true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1812,102 +1813,13 @@ const elementDone = async (element: any, slideIndex: number) => {
|
|
|
}
|
|
|
else if (toolType === 73) {
|
|
|
hasIframe = true
|
|
|
-
|
|
|
- // 先尝试获取iframe的contentWindow,如果获取不到再使用HTML方式
|
|
|
- try {
|
|
|
- // 创建一个临时的iframe来测试是否能获取contentWindow
|
|
|
- const tempIframe = document.createElement('iframe')
|
|
|
- // 不用 display:none:iPad Safari/WKWebView 会对隐藏 iframe 资源节流,
|
|
|
- // onload 迟迟不触发导致超时误判为"禁止嵌入",误入抓 HTML 路径(跨站 Cookie 被 ITP 拦截必然失败)
|
|
|
- tempIframe.style.position = 'absolute'
|
|
|
- tempIframe.style.left = '-9999px'
|
|
|
- tempIframe.style.top = '-9999px'
|
|
|
- tempIframe.style.width = '1px'
|
|
|
- tempIframe.style.height = '1px'
|
|
|
- tempIframe.src = iframeSrc
|
|
|
-
|
|
|
- // 先将临时iframe添加到body,否则onload事件不会触发
|
|
|
- document.body.appendChild(tempIframe)
|
|
|
- // 等待iframe加载完成
|
|
|
- await new Promise((resolve, reject) => {
|
|
|
- tempIframe.onload = resolve
|
|
|
- tempIframe.onerror = reject
|
|
|
- // iPad 网络/渲染较慢,超时放宽到 12 秒
|
|
|
- setTimeout(() => reject(new Error('Timeout')), 12000)
|
|
|
- })
|
|
|
-
|
|
|
- // 尝试获取contentDocument(标准属性:跨域返回 null 不抛异常;
|
|
|
- // 不能用 contentWindow.document,iPad Safari 跨域访问会直接抛 SecurityError,又会误入抓 HTML 路径)
|
|
|
- if (tempIframe.contentDocument) {
|
|
|
- console.log(`iframe ${iframeSrc} 可以获取contentWindow,使用直接加载方式`)
|
|
|
- // 移除临时iframe
|
|
|
- document.body.removeChild(tempIframe)
|
|
|
-
|
|
|
- _element = {
|
|
|
- ...element,
|
|
|
- isHTML: false,
|
|
|
- url: iframeSrc
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- // 加载完成但无法获取contentWindow,也要移除iframe
|
|
|
- document.body.removeChild(tempIframe)
|
|
|
- }
|
|
|
- }
|
|
|
- catch (error) {
|
|
|
- console.log(`iframe ${iframeSrc} 无法获取contentWindow,使用HTML方式:`, error)
|
|
|
-
|
|
|
- // 如果无法获取contentWindow,使用HTML方式
|
|
|
- let html = null
|
|
|
- try {
|
|
|
- html = await api.getHTML(iframeSrc)
|
|
|
- console.log('getHTML 成功获取内容:', html)
|
|
|
- }
|
|
|
- catch (error) {
|
|
|
- console.log(`getHTML 失败,尝试使用 getFile:`, error)
|
|
|
- try {
|
|
|
- const fileData = await getFile(iframeSrc)
|
|
|
- if (fileData && fileData.data) {
|
|
|
- const uint8Array = new Uint8Array(fileData.data)
|
|
|
- html = new TextDecoder('utf-8').decode(uint8Array)
|
|
|
- console.log('getFile 成功获取内容:', html)
|
|
|
- }
|
|
|
- }
|
|
|
- catch (error2) {
|
|
|
- console.log(`getFile 失败,尝试使用 getHTML:`, error2)
|
|
|
- try {
|
|
|
- const fileData2 = await getFile2(iframeSrc)
|
|
|
- if (fileData2 && fileData2.data) {
|
|
|
- const uint8Array = new Uint8Array(fileData2.data)
|
|
|
- html = new TextDecoder('utf-8').decode(uint8Array)
|
|
|
- console.log('getFile2 成功获取内容:', html)
|
|
|
- }
|
|
|
- }
|
|
|
- catch (error3) {
|
|
|
- console.error('getFile2 也失败:', error3)
|
|
|
- console.error('无法获取内容: getFile、getFile2 和 getHTML 都失败了')
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- console.log(`处理幻灯片 ${slideIndex + 1} 中的iframe链接:`, iframeSrc)
|
|
|
- if (html) {
|
|
|
- _element = {
|
|
|
- ...element,
|
|
|
- isHTML: true,
|
|
|
- url: html,
|
|
|
- curl: iframeSrc
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- // getHTML/getFile/getFile2 全失败:不能置空 url 硬切 srcdoc(会白屏),
|
|
|
- // 回退为直接加载原始链接,至少保持与进页面时一致的显示效果
|
|
|
- console.warn(`幻灯片 ${slideIndex + 1} 未获取到HTML内容,回退为直接加载:`, iframeSrc)
|
|
|
- _element = {
|
|
|
- ...element,
|
|
|
- isHTML: false,
|
|
|
- url: iframeSrc
|
|
|
- }
|
|
|
- }
|
|
|
+ // type=73 的探测+抓取延迟到 BaseFrameElement 打开时执行(isDone!==true 才触发)
|
|
|
+ // 这里只做域名修正,url 已经是前面通用替换后的 iframeSrc
|
|
|
+ console.log(`type=73 延迟处理中,url=`, iframeSrc)
|
|
|
+ _element = {
|
|
|
+ ...element,
|
|
|
+ url: iframeSrc
|
|
|
+ // 不设 isHTML / curl,保持 isDone 默认值让 BaseFrameElement 感知
|
|
|
}
|
|
|
}
|
|
|
|