| package bridge |
|
|
| import ( |
| "context" |
|
|
| "github.com/chromedp/cdproto/emulation" |
| "github.com/chromedp/cdproto/page" |
| "github.com/chromedp/chromedp" |
| ) |
|
|
| |
| const DisableAnimationsCSS = ` |
| (function() { |
| const style = document.createElement('style'); |
| style.setAttribute('data-pinchtab', 'no-animations'); |
| style.textContent = '*, *::before, *::after { animation: none !important; animation-duration: 0s !important; transition: none !important; transition-duration: 0s !important; scroll-behavior: auto !important; }'; |
| (document.head || document.documentElement).appendChild(style); |
| })(); |
| ` |
|
|
| |
| |
| func (b *Bridge) InjectNoAnimations(ctx context.Context) error { |
| return chromedp.Run(ctx, |
| chromedp.ActionFunc(func(ctx context.Context) error { |
| _, err := page.AddScriptToEvaluateOnNewDocument(DisableAnimationsCSS).Do(ctx) |
| return err |
| }), |
| chromedp.ActionFunc(func(ctx context.Context) error { |
| return emulation.SetEmulatedMedia(). |
| WithFeatures([]*emulation.MediaFeature{ |
| {Name: "prefers-reduced-motion", Value: "reduce"}, |
| }).Do(ctx) |
| }), |
| ) |
| } |
|
|
| |
| |
| func DisableAnimationsOnce(ctx context.Context) error { |
| return chromedp.Run(ctx, |
| chromedp.Evaluate(DisableAnimationsCSS, nil), |
| chromedp.ActionFunc(func(ctx context.Context) error { |
| return emulation.SetEmulatedMedia(). |
| WithFeatures([]*emulation.MediaFeature{ |
| {Name: "prefers-reduced-motion", Value: "reduce"}, |
| }).Do(ctx) |
| }), |
| ) |
| } |
|
|