0

看完这篇..

https://stackoverflow.com/a/54096072/13099685

谁能推荐我一种在 greasmonkey 或 Firefox 扩展中使用它的方法,用于重写解析为网页的标头数据(UA 切换)。

到目前为止我所拥有的是..

清单.json

{

  "description": "",
  "manifest_version": 2,
  "name": "user-agentr",
  "version": "1.0",
  "icons": {
    "48": "icons/person-48.png"
  },

  "permissions": [
    "webRequest", "webRequestBlocking", "https://*" 
  ],

  "background": {
    "scripts": ["background.js"]
  },

  "browser_action": {
    "default_icon": "icons/person-32.png",
    "default_title": "Choose a user agent",
    "default_popup": "popup/choose_ua.html"
  }

}

背景.js

function setUserAgent(userAgent) {
    Object.defineProperty(navigator, "userAgent", { 
        get: function () { 
            return userAgent; // customized user agent
        },
        configurable: true
    });
}

// Now in your setup phase:
// Keep the initial value
var initialUserAgent = navigator.userAgent;
setUserAgent('foo');

// In your tearDown:
// Restore the initial value
// setUserAgent(initialUserAgent);

--

这就是我成功更改用户代理所需的全部内容吗?

谢谢。

附言。我正在使用比较值

<!DOCTYPE html>
<html>
<body>

<div id="demo"></div>

<script>
var txt = "";
txt += "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt += "<p>Browser Name: " + navigator.appName + "</p>";
txt += "<p>Browser Version: " + navigator.appVersion + "</p>";
txt += "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt += "<p>Browser Language: " + navigator.language + "</p>";
txt += "<p>Browser Online: " + navigator.onLine + "</p>";
txt += "<p>Platform: " + navigator.platform + "</p>";
txt += "<p>User-agent header: " + navigator.userAgent + "</p>";

document.getElementById("demo").innerHTML = txt;
</script>

</body>
</html>

<html>
<head>
</head>

<body>


<?php

    $headers = apache_request_headers();

    foreach ($headers as $header => $value) {
        echo "$header: $value <br />\n";
    }

echo "<hr>";
echo $_SERVER['HTTP_USER_AGENT']
?>

</body>

</html>
4

0 回答 0