1

我正在尝试更改 firefox 用户代理字符串(和 oscpu),而无需重新启动它并编辑配置文件设置。一些 Firefox 插件会这样做,例如user agent overrider. 下面是它是如何做到的:

let UAManager = (function() {

    Cu.import('resource://gre/modules/UserAgentOverrides.jsm');

    // Orignal UA selector function, a method of UserAgentOverrides.
    // Keep it for revert to default.
    let orignalGetOverrideForURI = UserAgentOverrides.getOverrideForURI;

    let revert = function() {
        UserAgentOverrides.getOverrideForURI = orignalGetOverrideForURI;
    };

    let change = function(uastring) {
        UserAgentOverrides.getOverrideForURI = function() uastring;
    };

    let exports = {
        revert: revert,
        change: change,
    };
    return exports;
})();

哪里Cu=Components.utils;

所以,这就是我试图做的:

        FirefoxDriver fd=new FirefoxDriver();
        fd.ExecuteScript(@"Cu=Components.utils;
            Cu.import('resource://gre/modules/UserAgentOverrides.jsm');
            UserAgentOverrides.getOverrideForURI = function() ""my user agent"";");

在这一点上,我得到permission denied error. 有什么方法可以让我在 selinum 中使用插件权限执行这个脚本?

4

0 回答 0