fix(reader): 修复打开任意书籍报 makeBook is not defined(v1.3.5/v1.3.6) - #707
Open
hongweiwhw wants to merge 1 commit into
Open
fix(reader): 修复打开任意书籍报 makeBook is not defined(v1.3.5/v1.3.6)#707hongweiwhw wants to merge 1 commit into
hongweiwhw wants to merge 1 commit into
Conversation
问题:打开任意 EPUB 报 ReferenceError: makeBook is not defined,与设备无关,任何设备均复现(Closes codedogQBY#703)。 根因: 1. reader.template.html 调用的是裸 makeBook(...),而打包后的 foliate bundle 仅暴露 window.makeBook,并不存在全局裸 makeBook,故抛出 ReferenceError。 2. build-reader.js 入口同时静态导入 zip.js / EPUB / pdf.js,esbuild 打包后 bundle 结尾 先急切初始化全部格式引擎、最后才赋值 window.makeBook;任一引擎(尤其 pdf.js, 含 Node 环境检测 / CDN worker 等逻辑)在旧 WebView 初始化失败会导致整个 bundle 中断,window.makeBook 永远不会被赋值,阅读器内核完全不可用。 修复: - reader.template.html:两处裸 makeBook 改为 window.makeBook,并在打开书籍前增加 if (!window.makeBook) 守卫,内核缺失时给出明确提示。 - build-reader.js:window.makeBook 改为同步最先赋值;zip/EPUB/PDF 引擎改为 Promise 异步懒加载,失败被 catch 隔离,不再阻塞阅读器内核(仅失去懒加载/PDF 特性)。 - build-reader.js:esbuild target es2020 降为 es2017;注入旧 WebView 运行时垫片 (String.replaceAll / Array.prototype.at / Object.fromEntries / Promise.allSettled / structuredClone / Intl.Locale)。 - reader.html:使用修复后的模板重新生成。 测试:在海信 A7(Android,Chromium 85+ 老 WebView)实测,修复后 EPUB 可正常打开阅读; 本地以浏览器 API 桩环境运行 bundle,确认 window.makeBook 在引擎初始化前即就绪, 引擎加载失败被安全隔离。
Owner
|
旧版 Android WebView 已在真机验证通过。当前 PR 与最新 main(含 PR #711)存在 reader.html 冲突,请先 rebase main 并重新生成 reader.html,避免覆盖已有阅读器改动。更新后再合并。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
v1.3.5 / v1.3.6 移动端打开任意 EPUB 都会报
ReferenceError: makeBook is not defined,与设备无关、任何设备均可复现(对应 issue #703)。根因
makeBook:reader.template.html里调用的是裸makeBook(...),但打包后的 foliate bundle 只暴露window.makeBook,并不存在全局裸makeBook,因此抛出 ReferenceError。window.makeBook:build-reader.js入口同时静态导入 zip.js / EPUB / pdf.js,esbuild 打包后 bundle 结尾会先急切初始化全部引擎、最后才执行window.makeBook = ...。任一引擎(尤其 pdf.js,含 Node 环境检测 / CDN worker 逻辑)在旧 WebView 初始化失败,会使整个 bundle 中断,window.makeBook永远不会被赋值,阅读器内核完全不可用。修复内容
reader.template.html:两处裸makeBook(改为window.makeBook(;打开书籍前新增if (!window.makeBook)守卫,内核缺失时给出明确提示(并附带初始化期间捕获的错误信息,便于定位)。build-reader.js:window.makeBook改为同步最先赋值;zip/EPUB/PDF 引擎改为 Promise 异步懒加载,失败被catch隔离,不再阻塞阅读器内核(仅失去懒加载 / PDF 特性)。build-reader.js:esbuild target 由es2020降为es2017;注入旧 WebView 运行时垫片(String.replaceAll/Array.prototype.at/Object.fromEntries/Promise.allSettled/structuredClone/Intl.Locale)。reader.html:使用修复后的模板重新生成。测试
window.makeBook在引擎初始化前即就绪,引擎加载失败被安全隔离、不影响内核可用。Closes #703