How to access navigator.plugins object in main.js file? I use a Firefox Add-on SDK.
var windows = require("sdk/window/utils");
var window = windows.getMostRecentBrowserWindow();
console.log(window.navigator.plugins);
Every add-on comes with it's own "hidden" window, that could be used for some stuff. It's not well documented, but you should be able to do something like:
let { window: {navigator} } = require('sdk/addon/window');
console.log(navigator.plugins);
Related
I have tried attaching toJavaScriptConsole() to a button but this is not working (undefined reference error)
How can I program an XUL button to open the firefox browser console so we can see logs from the extension?
The following snippet will work.
if(HUDService.getBrowserConsole()) // is it already open?
HUDService.getBrowserConsole().chromeWindow.focus();
else
HUDService.toggleBrowserConsole();
If you are in a scope where HUDService is not available then to get access to it do the following:
var devtools = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
var HUDService = devtools.require("devtools/webconsole/hudservice");
I need to detect if the Adblock extension is installed on the user's browser.
I have seen similar question on SO, but most of them suggest to check if the DOM has been modified.
I would rather want to check if the extension is installed (maybe with Javascript ?) on the browser rather than check the DOM. How do i do this ?
Try the global navigator.plugins variable. With a loop it should work. (JS)
Nice blog to the topic: http://webdevwonders.com/detecting-browser-plugins/
EDIT: For chrome you can try this if you now the APP GUID.
try {
var appGUID = "nnbmlagghjjcbdhgmkedmbmedengocbn";
a = new Image();
a.src = "chrome-extension://"+appGUID+"/icon16.gif";
if(a.width != 0) {
//App installed!
}
} catch(e) {
//App not installed
}
I'm using JavaScript to see if the ShockwaveFlash plugin is on my page as an ActiveXObject. I'm also checking for the application/x-shockwave> I'm using swfobject to load the Flash on to the page.
I can check for which Flash Version I'm running but I'm not sure how to check for which installation of Flash is installed for the browser.
What I want to do is check to see if Flash for Other Browsers is installed on the machine.
Is this possible with JavaScript?
JavaScript Code
var hasFlash = false;
try {
var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
if(fo) hasFlash = true;
sendEventToServer("flash_not_found");
} catch(e){
if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true;
}
Plugins are located here but I don't believe it is a W3C standard.
var myNavigator = window.navigator ? window.navigator : navigator;
var plugins = myNavigator.plugins
for (var key in plugins) {
document.write("<li>"+key+" : "+plugins[key]);
}
Looking at the associated objects with for (in) we have an associated array where we have name and version.
document.write(navigator.plugins[0].name);
document.write(navigator.plugins[0].version);
document.write(navigator.plugins[0].description);
so you need to loop through them. The gobal object to start at is either window.navigator or navigator depending on browser. Your catch(e){
if(navigator. assumes its always navigator, but its not.
This can be done with user32.dll on Windows. But how can i get it on Mac/Linux?
You should use nsILocaleService.getSystemLocale() for that:
var localeService = Components.classes["#mozilla.org/intl/nslocaleservice;1"]
.getService(Components.interfaces.nsILocaleService);
var sysLocale = localeService.getSystemLocale()
alert(sysLocale.getCategory("NSILOCALE_MESSAGES"));
This should work regardless of operating system.
I'm using the Firefox Addon SDK to build something that monitors and displays the HTTP traffic in the browser. Similar to HTTPFox or Live HTTP Headers. I am interested in identifying which tab in the browser (if any) generated the request
Using the observer-service I am monitoring for "http-on-examine-response" events. I have code like the following to identify the nsIDomWindow that generated the request:
const observer = require("observer-service"),
{Ci} = require("chrome");
function getTabFromChannel(channel) {
try {
var noteCB= channel.notificationCallbacks ? channel.notificationCallbacks : channel.loadGroup.notificationCallbacks;
if (!noteCB) { return null; }
var domWin = noteCB.getInterface(Ci.nsIDOMWindow);
return domWin.top;
} catch (e) {
dump(e + "\n");
return null;
}
}
function logHTTPTraffic(sub, data) {
sub.QueryInterface(Ci.nsIHttpChannel);
var ab = getTabFromChannel(sub);
console.log(tab);
}
observer.add("http-on-examine-response", logHTTPTraffic);
Mostly cribbed from the documentation for how to identify the browser that generated the request. Some is also taken from the Google PageSpeed Firefox addon.
Is there a recommended or preferred way to go from the nsIDOMWindow object domWin to a tab element in the SDK tabs module?
I've considered something hacky like scanning the tabs list for one with a URL that matches the URL for domWin, but then I have to worry about multiple tabs having the same URL.
You have to keep using the internal packages. From what I can tell, getTabForWindow() function in api-utils/lib/tabs/tab.js package does exactly what you want. Untested code:
var tabsLib = require("sdk/tabs/tab.js");
return tabsLib.getTabForWindow(domWin.top);
The API has changed since this was originally asked/answered...
It should now (as of 1.15) be:
return require("sdk/tabs/utils").getTabForWindow(domWin.top);
As of Addon SDK version 1.13 change:
var tabsLib = require("tabs/tab.js");
to
var tabsLib = require("sdk/tabs/helpers.js");
If anyone still cares about this:
Although the Addon SDK is being deprecated in support of the newer WebExtensions API, I want to point out that
var a_tab = require("sdk/tabs/utils").getTabForContentWindow(window)
returns a different 'tab' object than the one you would typically get by using
worker.tab in a PageMod.
For example, a_tab will not have the 'id' attribute, but would have linkedPanel property that's similar to the 'id' attribute.