I'm trying to port my user-agent switcher extension to WebExtensions, and preferably in a Chromium-compatible way. But I'm having trouble figuring out how to alter navigator.userAgent.
Basically I need to have a content script do the Webext equivalent of these legacy codes -
Code: Select all
getSandbox: function(contentWindow) {
// contentWindow might be an Xray, unwrap if it is
let win = contentWindow.wrappedJSObject || contentWindow;
let sandbox = new Cu.Sandbox(win, {sandboxPrototype: win, wantComponents: false, wantXHRConstructor: false, wantXrays: false});
return sandbox;
},
Code: Select all
// called from a content-document-global-created observer
let contentSandbox = utils.getSandbox(contentWindow);
Cu.evalInSandbox("(function(){/* code to set custom navigator.userAgent */ })()", contentSandbox, "1.8");
How to do this in Webext?