mirror of
https://github.com/bestnite/bilinovel-downloader.git
synced 2026-07-25 20:21:56 +00:00
fix: upgrade playwright-go and fix file:// resource loading
- Upgrade playwright-go v0.5200.1 -> v0.6100.0 (module path changed from playwright-community to mxschmitt). The old Azure CDN driver download endpoint returns 404 for all versions; v0.6100.0 switches to npm registry which works correctly. - Fix file:// resource loading: replace absolute path src="/..." and href="/..." with full URLs so browser can fetch remote resources (chapterlog.js) when loading local HTML files. - Replace removed Devtools field with Args --auto-open-devtools-for-tabs. - Include error details in playwright install failure log. - Fix nil pointer in tests: check err before calling SetTextOnly. - Update all dependencies: goquery, templ, resty, cobra, pflag, etc. - Bump go toolchain 1.24.2 -> 1.25.0
This commit is contained in:
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
mapper "git.nite07.com/nite/font-mapper"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/playwright-community/playwright-go"
|
||||
"github.com/mxschmitt/playwright-go"
|
||||
)
|
||||
|
||||
//go:embed read.ttf
|
||||
@@ -101,10 +101,13 @@ func (b *Bilinovel) initBrowser(debug bool) error {
|
||||
return fmt.Errorf("could not start playwright: %w", err)
|
||||
}
|
||||
|
||||
b.browser, err = pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
|
||||
launchOpts := playwright.BrowserTypeLaunchOptions{
|
||||
Headless: playwright.Bool(!debug),
|
||||
Devtools: playwright.Bool(debug),
|
||||
})
|
||||
}
|
||||
if debug {
|
||||
launchOpts.Args = []string{"--auto-open-devtools-for-tabs"}
|
||||
}
|
||||
b.browser, err = pw.Chromium.Launch(launchOpts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not launch browser: %w", err)
|
||||
}
|
||||
@@ -530,6 +533,10 @@ func (b *Bilinovel) processContentWithPlaywright(page playwright.Page, htmlConte
|
||||
// 替换 window.location.replace,防止页面跳转
|
||||
htmlContent = strings.ReplaceAll(htmlContent, "window.location.replace", "console.log")
|
||||
|
||||
// 将绝对路径的资源引用替换为完整 URL,以便从 file:// 加载时能正确请求远程资源
|
||||
htmlContent = strings.ReplaceAll(htmlContent, `src="/`, `src="https://www.bilinovel.com/`)
|
||||
htmlContent = strings.ReplaceAll(htmlContent, `href="/`, `href="https://www.bilinovel.com/`)
|
||||
|
||||
tempPath := filepath.Join(os.TempDir(), "bilinovel-downloader")
|
||||
err := os.MkdirAll(tempPath, 0755)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user