UserAgent spoof methods besides page menu refreshing
Me9ur1 opened this issue · comments
菜单栏的刷新是一定生效的,仅对于标题的方式不生效,我需要对chrome启动时页面初次加载的过程中进行一些hook吗?能否提供一些思路,感谢!
I don't it is possible or good to do this with Xposed hooks.
Instead, you may consider check UA within your JavaScript codes. Here is an example taking from my own script:
const ua =
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114 Safari/537.36";
if (document.readyState == "loading") {
window.addEventListener("DOMContentLoaded", switchToDesktop);
} else {
switchToDesktop();
}
function switchToDesktop() {
if (
navigator.userAgent == ua &&
document.documentElement.className != "mobile-web-player"
) {
...
} else {
ChromeXt.dispatch("syncData", {
origin: window.location.origin,
data: ua,
name: "userAgent",
});
ChromeXt.dispatch("userAgentSpoof", window.location.href);
}
}
// vim: set expandtab: set tabstop=2:
我看到了项目里对于loadurlparams的hook代码,我只是好奇为什么对于初次加载页面时,尽管我对这个类里的ua参数进行hook,但是并不生效,只有在刷新时或者通过chromext使用js时才会生效
The Chromium
uses some lazy or cached logic to avoid parsing or analyzing LoadUrlParams
multiple times.
Therefore, we can only hook UA when Chromium
is not using cached parameters.
我大概了解了,感谢!
I just updated the JavaScript
codes above to show you how to spoof UA using the ChromeXt
API.
Note that it is impossible to spoof UA without using the ChromeXt
API.
Hey bro,there is something wrong with my js code. Here is my code : https://greasyfork.org/zh-CN/scripts/482653-hidefingerprintforchromext/code
Please refer to the docs in README: https://github.com/JingMatrix/ChromeXt?tab=readme-ov-file#supported-api
You need to add @grant GM.ChromeXt
.
现在加上了,但是在chrome的sp文件夹下没有发现useragent.xml被创建(但是我可以通过在kotlin层创建自定义的useragent.xml来实现ua伪装,只不过此时创建貌似时机不太对),我对js不太熟悉,抱歉:(
I cannot understand the description of your situation.
Moreover, you should clarify the folder or file locations you are referring to.
If the GM.ChromeXt
API is not working as expected, please open an new issue and present how to reproduce it.
I am using ChromeXt
API everyday and always using UserAgent Spoof endpoint, it is not likely to be a bug of the project. Better double check your JavaScript codes.
好的,我再检查一下吧