I want to disable javascript in https://github.com/chromedp/chromedp
any allocator flag can I put in the config? thank you!
CodePudding user response:
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/ /main:out/Debug/gen/third_party/blink/renderer/core/settings_macros.h;l=1535