I want to enable the addon which is disabled manually after firefox restart .I can listen the events for enable/disable firefox addon with the methods "onDisabling: function(addon, needsRestart)" .Can I enable the extension using javascript.any ideas would be appreciated?
You can use Add-on Manager API for this. Something along these lines:
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("someextension#example.com", function(addon)
{
if (addon.userDisabled)
addon.userDisabled = false;
});
Here someextension#example.com stands for the ID of the add-on you want to enable of course.
Related
I am able to built the desktop app in electronJS. I am trying to implement the functionality to disable the click event on window when there is no internet connectivity similar to the slack.I found the API to detect the internet in electron but not able to find the way to disable the click events.
You can disable all pointer events by adding the following rule to your page's CSS:
body {
pointer-events:none;
}
or via JavaScript:
document.body.style.pointerEvents = "none";
to re-enable:
body {
pointer-events:auto;
}
or
document.body.style.pointerEvents = "auto";
You can do this on more specific elements to gain more granular control.
You could add an invisible panel in front of everything and catch the clicks there.
I'm automating a website and sometimes it uses an ip address as url, that ip address generates a connection is not secure message in Firefox. Researching online I found out that for Firefox, the default in chimp is acceptInsecureCerts = False. That doesn't happen to Chrome as the default is acceptInsecureCerts = True.
How can I change that in Chimp to make it also work in Firefox? Do I need to create a profile? If so, how can I do that? Thanks!
This is more of a WebdriverIO config than Chimp. See here how you can set acceptInsecureCerts using the desiredCapabilities section of the config like this:
module.exports {
webdriverio: {
desiredCapabilities: {
browserName": "firefox",
acceptInsecureCerts": true
}
}
}
The config above goes in the Chimp config file. See here for details
See the full Chimp config here
See the Webdriver.io config here
See the desiredCapbilities support for webdriver here
Note that browsers have their own extra desiredCapabilities, like Chrome for example.
I need to control Firefox browser via webdriver. Note, I'm not trying to control page elements (i.e. find element, click, get text, etc); rather I need access to Firefox's profiler and force gc (i.e. I need firefox's Chrome Authority and sdk). For context, I'm creating a micro benchmark framework, not running a normal webdriver test.
Obviously raw webdriver won't work, so what I've been trying to do is
1) Create a firefox extension/add-on that does what I need: i.e.
var customActions = function() {
console.log('calling customActions.')
// I need to access chrome authority:
var {Cc,Ci,Cu} = require("chrome");
Cc["#mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
Cu.forceGC();
var file = require('sdk/io/file');
// And do some writes:
var textWriter = file.open('a/local/path.txt', 'w');
textWriter.write('sample data');
textWriter.close();
console.log('called customActions.')
};
2) Expose my customActions function to a page:
var mod = require("sdk/page-mod");
var data = require("sdk/self").data;
mod.PageMod({
include: ['*'],
contentScriptFile: data.url("myscript.js"),
onAttach: function(worker) {
worker.port.on('callCustomActions', function() {
customActions();
});
}
});
and in myscript.js:
exportFunction(function() {
self.port.emit('callCustomActions');
}, unsafeWindow, {defineAs: "callCustomActions"});
3) Load the xpi during my webdriver test, and call out to global function callCustomActions
So two questions about this process.
1) This entire process is very roundabout. Is there a better practice for talking to a firefox extension via webdriver?
2) My current solution isn't working well. If I run my extension via cfx run directly (without webdriver) it works as expected. However, neither the sdk nor chrome authority do anything when running via webdriver.
By the way, I know my function is being called because the log line "calling customActions." and "called customActions." both do print.
Maybe there are some firefox preferences that I need to set but haven't?
It may be that you do not need the add-on at all. Mozilla uses Marionette for test automation of Firefox OS amongst other things:
Marionette is an automation driver for Mozilla's Gecko engine. It can
remotely control either the UI or the internal JavaScript of a Gecko
platform, such as Firefox or Firefox OS. It can control both the
chrome (i.e. menus and functions) or the content (the webpage loaded
inside the browsing context), giving a high level of control and
ability to replicate user actions. In addition to performing actions
on the browser, Marionette can also read the properties and attributes
of the DOM.
If this sounds similar to Selenium/WebDriver then you're correct!
Marionette shares much of the same ethos and API as
Selenium/WebDriver, with additional commands to interact with Gecko's
chrome interface. Its goal is to replicate what Selenium does for web
content: to enable the tester to have the ability to send commands to
remotely control a user agent.
Is there any way to dynamically change the proxy being used by Firefox when using selenium webdriver?
Currently I have proxy support using a proxy profile but is there a way to change the proxy when the browser is alive and running?
My current code:
proxy = Proxy({
'proxyType': 'MANUAL',
'httpProxy': proxy_ip,
'ftpProxy': proxy_ip,
'sslProxy': proxy_ip,
'noProxy': '' # set this value as desired
})
browser = webdriver.Firefox(proxy=proxy)
Thanks in advance.
This is a slightly old question.
But it is actually possible to change the proxies dynamically thru a "hacky way"
I am going to use Selenium JS with Firefox but you can follow thru in the language you want.
Step 1: Visiting "about:config"
driver.get("about:config");
Step 2 : Run script that changes proxy
var setupScript=`var prefs = Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("network.proxy.type", 1);
prefs.setCharPref("network.proxy.http", "${proxyUsed.host}");
prefs.setIntPref("network.proxy.http_port", "${proxyUsed.port}");
prefs.setCharPref("network.proxy.ssl", "${proxyUsed.host}");
prefs.setIntPref("network.proxy.ssl_port", "${proxyUsed.port}");
prefs.setCharPref("network.proxy.ftp", "${proxyUsed.host}");
prefs.setIntPref("network.proxy.ftp_port", "${proxyUsed.port}");
`;
//running script below
driver.executeScript(setupScript);
//sleep for 1 sec
driver.sleep(1000);
Where use ${abcd} is where you put your variables, in the above example I am using ES6 which handles concatenation as shown, you can use other concatenation methods of your choice , depending on your language.
Step 3: : Visit your site
driver.get("http://whatismyip.com");
Explanation:the above code takes advantage of Firefox's API to change the preferences using JavaScript code.
As far as I know there are only two ways to change the proxy setting, one via a profile (which you are using) and the other using the capabilities of a driver when you instantiate it as per here. Sadly neither of these methods do what you want as they both happen before as you create your driver.
I have to ask, why is it you want to change your proxy settings? The only solution I can easily think of is to point firefox to a proxy that you can change at runtime. I am not sure but that might be possible with browsermob-proxy.
One possible solution is to close the webdriver instance and create it again after each operation by passing a new configuration in the browser profile
Have a try selenium-wire, It can even override header field
from seleniumwire import webdriver
options = {
'proxy': {
"http": "http://" + IP_PORT,
"https": "http://" + IP_PORT,
'custom_authorization':AUTH
},
'connection_keep_alive': True,
'connection_timeout': 30,
'verify_ssl': False
}
# Create a new instance of the Firefox driver
driver = webdriver.Firefox(seleniumwire_options=options)
driver.header_overrides = {
'Proxy-Authorization': AUTH
}
# Go to the Google home page
driver.get("http://whatismyip.com")
driver.close()
I have a Modernizr check for geolocation support. I noticed it wasn't working as expected so I put in some logs to see what was happening. It seems that it is alerting true whether geolocation is enabled in the browser or not. I know I'm disabling geolocation in my browser correctly because it works as expected for Modernizr.geolocation demos I've found online.
//Check for geolocation support; hide "use my location" button if unsupported
if (Modernizr.geolocation) {
console.log('true');
//App.locateInit();
} else {
console.log('false');
//$('#geo-container').css('display','none');
}
I'm calling the custom Modernizr script with the geolocation piece. Any ideas as to what could be causing this? Please let me know what to look for or what other info you may need, I'm very new to Modernizr.
Thanks!
Which browser? Apparently your browser doesn't remove the API when its disabled, which means its impossible to detect the disabling. :(