feat: 添加帮助功能

This commit is contained in:
lixiangwuxian
2024-10-15 23:07:49 +08:00
parent ea3ef541e2
commit 48891fbd0a
12 changed files with 217 additions and 33 deletions

View File

@@ -74,12 +74,12 @@ func ScreenshotURL(url, output string, width, height int, marginTop, marginBotto
err := chromedp.Run(ctx,
chromedp.Navigate(url), // 打开网页
ignoreErrors(queryAction), // 等待指定元素
chromedp.Sleep(5*time.Second),
chromedp.Sleep(10*time.Second),
chromedp.ActionFunc(func(ctx context.Context) error { // 自定义截图逻辑
layoutViewport, _, _, _, _, _, _ := page.GetLayoutMetrics().Do(ctx)
_, _, _, _, cssLayoutViewport, _, _ := page.GetLayoutMetrics().Do(ctx)
if width == 0 || height == 0 {
width = int(layoutViewport.ClientWidth)
height = int(layoutViewport.ClientHeight)
width = int(cssLayoutViewport.ClientWidth)
height = int(cssLayoutViewport.ClientHeight)
}
// 计算调整后的截图区域
clip := &page.Viewport{
@@ -125,6 +125,7 @@ func enableRequestInterception() chromedp.Tasks {
network.SetBlockedURLS([]string{
"pagead2.googlesyndication.com",
"optimizationguide-pa.googleapis.com",
"static.cloudflareinsights.com",
}),
}
}