-
-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EmulationSetEmulatedMedia is not working #641
Comments
Please fix the golang code in your markdown: @@ golang markdown block 1 @@
1:1: expected 'package', found page
1:6: expected 'IDENT', found ':='
1:9: expected ';', found browser
@@ golang markdown block 2 @@
1:1: expected 'package', found _
1:3: expected 'IDENT', found '='
1:5: expected ';', found proto generated by check-issue |
Works fine for me: func TestLab(t *testing.T) {
g := setup(t)
page := g.page
out := page.MustEval(`() => window.matchMedia('(prefers-color-scheme: light)').matches`).Bool()
g.True(out)
err := proto.EmulationSetEmulatedMedia{
Features: []*proto.EmulationMediaFeature{
{Name: "prefers-color-scheme", Value: "dark"},
},
}.Call(page)
g.E(err)
out = page.MustEval(`() => window.matchMedia('(prefers-color-scheme: light)').matches`).Bool()
g.False(out)
} |
thanks for your reply. window.matchMedia('(prefers-color-scheme: dark)').matches the result is and, |
Could you provide the full code that can reproduce the issue like what I did? |
there is my demo code package main
import (
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/proto"
"time"
)
func main() {
URL := launcher.New().
Set("no-sandbox").
Set("disable-gpu").
Headless(true).
MustLaunch()
browser := rod.New().
ControlURL(URL).
MustConnect()
page := browser.MustPage()
m := proto.EmulationSetEmulatedMedia{
Features: []*proto.EmulationMediaFeature{
{Name: "any-pointer", Value: "fine"},
{Name: "any-hover", Value: "hover"},
},
}
err := m.Call(page)
if err != nil {
panic(err)
}
output := page.MustEval(`() => window.matchMedia('(any-pointer: fine)').matches`).Bool()
// output is false
fmt.Println(output)
output = page.MustEval(`() => window.matchMedia('(any-hover: hover)').matches`).Bool()
// output is false too
fmt.Println(output)
page.MustNavigate("https://arh.antoinevastel.com/bots/")
time.Sleep(5 * time.Second)
page.MustScreenshot("")
} and the screenshot of fingerprint you known, my remote computer have no any pointer devices, I want to emulate a device via override media feature, but I failed. |
Please read rule 4 in #322. |
@go-rod/everyone I have simplified my code, and build a binary, running on remote, the same problem |
Still, works fine for me, can you try the code below: func TestLab(t *testing.T) {
defaults.Show = true
g := setup(t)
page := g.page
err := proto.EmulationSetEmulatedMedia{
Features: []*proto.EmulationMediaFeature{
{Name: "prefers-color-scheme", Value: "light"},
},
}.Call(page)
g.E(err)
out := page.MustEval(`() => window.matchMedia('(prefers-color-scheme: light)').matches`).Bool()
g.True(out)
err = proto.EmulationSetEmulatedMedia{
Features: []*proto.EmulationMediaFeature{
{Name: "prefers-color-scheme", Value: "dark"},
},
}.Call(page)
g.E(err)
out = page.MustEval(`() => window.matchMedia('(prefers-color-scheme: light)').matches`).Bool()
g.False(out)
} |
I found your code works fine only use |
Better to always show you test code, or modify my code, maybe you have bugs in your test code. Read the step 3 in https://github.com/go-rod/rod/blob/master/.github/ISSUE_TEMPLATE/question.md |
I find the same issue on Puppeteer. |
Seems like an upstream bug. |
that is a bad news for anti fingerprint scan 😢 |
Rod Version: v0.107.3
The code to demonstrate your question
I am following document https://go-rod.github.io/i18n/zh-CN/#/emulation?id=%e9%85%8d%e8%89%b2%e6%96%b9%e6%a1%88%e5%92%8c%e5%aa%92%e4%bd%93
What you got
But result of the following media query is
false
:And I running my code with
headless
on Linux which have no any pointer devices, I try to emulate a device like this:But is not working too, media query is
false
:The text was updated successfully, but these errors were encountered: