英文:
How to disable javascript in chromedp?
问题
我想在https://github.com/chromedp/chromedp中禁用JavaScript。我可以在配置中设置任何分配器标志吗?谢谢!
英文:
I want to disable javascript in https://github.com/chromedp/chromedp
any allocator flag can I put in the config? thank you!
答案1
得分: 1
有一个命令行选项:--blink-settings=scriptEnabled=false
。
package main
import (
"context"
"log"
"os"
"github.com/chromedp/chromedp"
)
func main() {
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("blink-settings", "scriptEnabled=false"),
)
ctx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer cancel()
ctx, cancel = chromedp.NewContext(ctx)
defer cancel()
var res []byte
err := chromedp.Run(ctx,
chromedp.Navigate(`https://twitter.com/`),
chromedp.FullScreenshot(&res, 100),
)
if err != nil {
log.Fatal(err)
}
os.WriteFile("screenshot.png", res, 0644)
}
FYI,可用的blink-settings
列表可以在这里找到:https://source.chromium.org/chromium/chromium/src/+/09372ea8ec2ab6363ccad6a4847a1c9da560b29d:out/Debug/gen/third_party/blink/renderer/core/settings_macros.h;l=1535
英文:
There is a command line option: --blink-settings=scriptEnabled=false
.
package main
import (
"context"
"log"
"os"
"github.com/chromedp/chromedp"
)
func main() {
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("blink-settings", "scriptEnabled=false"),
)
ctx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer cancel()
ctx, cancel = chromedp.NewContext(ctx)
defer cancel()
var res []byte
err := chromedp.Run(ctx,
chromedp.Navigate(`https://twitter.com/`),
chromedp.FullScreenshot(&res, 100),
)
if err != nil {
log.Fatal(err)
}
os.WriteFile("screenshot.png", res, 0644)
}
FYI, the list of available blink-settings
can be found here: https://source.chromium.org/chromium/chromium/src/+/09372ea8ec2ab6363ccad6a4847a1c9da560b29d:out/Debug/gen/third_party/blink/renderer/core/settings_macros.h;l=1535
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论