Detect installed extensions in browsers? - javascript

Is it possible to detect via JS what extensions / add ons a user has installed on his browser? The use case was the a particular chrome extension, Autofill was setting some text values into hidden zip fields causing some validations to fail and I want to show a message to the user that this extension might create problems.

For Firefox: First snippet of code on: AddonManager.jsm - MDN
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAllAddons(function(aAddons) {
// Here aAddons is an array of Addon objects
});
// This code will execute before the code inside the callback
Must run this code in privelaged javascript, as in not a tab. You can try for specialPowers though I don't know how that works.
To run privelaged script from your site you will have to create a firefox addon and addEventListener's to your site, like a button to list the addons, you would attach a privelaged function to that.
With the addon you enable/disable addons, but users find that annoying because addons do some obtrsuvie stuff on install sometimes.

For Chrome extensions specifically, only certain extensions are detectable so this is not a very good method, but as far as I know, there are no longer any reliable methods to detect browser extensions.
For the extension that you want to detect, you would need its Extension Id and its Web accessible resource.
Some extensions have web accessible resources and some do not. If there is no web accessible resource, you will not be able to detect that extension.
To find the web accessible resource, you will need to look at the extensions chrome.manifestfile. It will tell you if there is web accessible content. For example, the chrome.manifest file might say:
content web-developer content/web-developer/ contentaccessible=yes
Generally, its not very effective to look for browser extensions since you have to know which extensions you want to detect ahead of time and many times they are undetectable.
Also, here's a good link that I used when I was trying to do the same thing here

NavigatorPlugins.mimeTypes
Take a peek at the MDN page
https://developer.mozilla.org/en-US/docs/Web/API/NavigatorPlugins.mimeTypes?redirectlocale=en-US&redirectslug=Web%2FAPI%2FNavigator.mimeTypes
Hope it helps

In JavaScript check to see if the zip field has been changed while it is hidden and show a warning to the user that an extension might be causing issues.

For Firefox you can do it with Mochitest/SpecialPowersAPI
https://developer.mozilla.org/en-US/docs/SpecialPowers

Related

Should chrome extensions have access to Tabs content (other websites)

Is there a way to identify and block JS files/events that are not part of your domain?
Like assume, if I'm writing a extension for chrome and I put following code in my JS
$('div').on('click', function(){ alert("yup"); });
is there a way for a website to handle this case?
Edit 1:
After discussion with #Clive, I realized that all extension/application should run in sandbox and should not be able to access events/elements outside the scope.
Case
A chrome extension have a keypress event on input[type=text] and input[type=password]. Now this extension runs in background, so there JS files are always available. Hence if you open facebook and login to your account, this extension will capture data and can send it to its server.
My Case
Two user was getting alert messages multiple times. Initially we thought its a part of our code and checked all JS files. But then realized, both user had same extension and so we diagnosed that extension's JS file and found alert in it. Now we were lucky, no damage was done, but it still posses a possible security threat.
Short answer: No.
Long answer:
Chrome extensions run their code in a separate space from your site's code, so they don't interact at all. The best you could do is prevent DOM edits. Luckily chrome extensions already run in a sandbox and have to explicitly ask for permissions for the domains that they inject code in and those domains are all listed when you install an extension. The only other way for extensions to interact with a page is through the activeTab permission which is a one time allowance on a specific user action. If you are using an extension that you think is malicious, you can always just read the code since JS is naturally open source. It really all boils down to a matter of trust. Installing something is explicitly trusting that thing to not mess up your stuff. This applies to all programs. If you don't trust an extension, then don't install it. A sandbox can only prevent so much while still letting extensions do something.

Is there any way to run a userscript without using Greasemonkey or Tampermonkey?

Is there any way to run a user script without running it through Greasemonkey/Tampermonkey?
I know its a simple question but I can't find any information on this...or if it's even possible.
Can the user script be edited so it doesn't rely on Greasemonkey?
It's up to the browser you are using to enable support for running arbitrary javascript on page load.
Chrome has limited userscript support, but is nowhere near as easy or powerful as Tampermonkey.
Tampermonkey and Greasemonkey (and other browser extensions) were created to address the userscript need.
You do have options for running javascript after a page has loaded though. You can use the developer tools console or you can create a Bookmarklet.
On firefox:
You can use the Scriptish addon (an alternative to greasemonkey for automatically running userscripts).
There is the Developer Scratchpad for editing, saving, loading and running scripts (and userscripts) manually. Also, can be applied on either the current document or browser chrome. Accessed via shift-F4 or Developer > Scratchpad.
And then there is also GCLI (Graphical Command Line Interpreter) which you can write routines for via a mozcmd file and is run manually. You'll need to modify the userscript a bit to access window, document objects. Accessed via shift-F2 or Developer > Developer Toolbar.
This one is a bit more involved, but if you want to go the addon route, you can write an addon using the Addon SDK, and use the page-mod API which injects a userscript into a page automatically.
In Google Chrome or Firefox you can open the DevTools (e.g. by right-clicking the page and selecting Inspect) and then paste the code in the Console tab and press Enter to run it.
In Google Chrome DevTools you can also create a js snippet and run it on demand whenever you need it.
You can also use Chrome DevTools Snippets:
Right-click anywhere on the page and select Inspect.
Select the Sources tab — you will see a number of subtabs: Page, Filesystem, Override, Content scripts and finally Snippets (you might need to click >> in order to see it).
Click the plus button ➕ to add the js code, and use right-click > Run to execute the code.
NOTE: If the original script uses extra js libraries (jquery, etc) and the libs are not already preloaded on the page, then you'll need to load them yourself (see this).
Unlike the code you run from the Console, you can set breakpoints in your JS snippets.

Disable chrome extension conflicting with my site

I work on a web site, using jQuery-1.8 , and found out, a certain extension ( on the CEO-s laptop ) is using jQuery-1.7 as a content script. This content script overwrites my script. Is there a way I can block at least some certain extensions from loading on the chrome tab my web app is using? A meta tag maybe?
No. Unless the said extension is cooperative (that is it looks for the meta tag, or a specific URL, to disconnect itself), you have no way of disabling it.
You might find a way dependent on the extension but you'd need the extension's code to look for it.
In your specific case the problem seems to be that jQuery is overwritten. Can't you simply wrap your code in order to use the specific jQuery you need ?
(function($) {
// here $ is protected :
// it has the value it had when the page was loaded
})($);
This behavior by an extension is not really acceptable, you should contact the extension developers to get it fixed. If they can't be reached, then you should request removal from the Chrome Web Store.

What is "chrome-extension://"

I found the some strange <script/> tags on a site:
<script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/document_iterator.js"></script>
<script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/find_proxy.js"></script>
...
I haven't been able to find much information on this, but I highly doubt this is actually related to Google Chrome since this site in particular is still using <table>s for layout, and the source in question was retrieved with curl not a graphical web browser.
So,
What on earth is this?
What is chrome-extension://
Why is it using lifbcibllhkdhoafpjfnlhfpfgnpldfl as a directory name
Why is it pretending to be valid URL to a javascript file?
Why would I need find_proxy or document_iterator
Solved. As far as I know...
chrixian was right, It seems that only on this and a few select other pages, someone had re-saved them from Chrome's source-view with the Skype extension installed.
Thanks everyone for all your help, +1's for all! enjoy!
That is actually Skype Click to Call chrome extension.
Manage and view it using this link
chrome://extensions/?id=lifbcibllhkdhoafpjfnlhfpfgnpldfl
If you are using cURL to get the page, you're getting the HTML as it exists on the server--so I think a safe assumption would be: the author of the page initially saved the page from Chrome, he had an extension installed that inserted these script tages and lastly he didn't remove the script tags for one reason or another before putting the page on the server.
This is added by chrome as the page loads, to inject the extension's Javascript code into the page, so it can access the HTML document.
The Skype extension causes it by inserting all kinds of junk in webpages that you visit.
Do you have the Skype browser extension installed for Chrome?
Just disable the extension.
Chrome, like Firefox, provides developers with an easy API to extend the functionality of the web browser without needing to actually download and build the browser to do so.
They also provide a robust delivery system. In Google's case, it's the Google Chrome Web Store.
Extensions are installed locally on your computer, and use long strings as directory names to reduce the risk of collisions with another extension. In other words, if you and I both named our extensions "mycoolextension", then there would be a problem if a person tried to install your extension and my extension. The long string helps prevent collisions such as this.
The chrome-extension:// protocol is used by the browser to make requests to these local resources. Chrome extensions are developed using HTML5, JavaScript, and CSS, along with an API exposed to allow the local JavaScript to perform actions it would not normally be able to do on the Internet.
When you see these in the Chrome developer tools, it's just the extension doing it's thing, whatever that may be.
If you're seeing these, then you likely installed some extensions from the Chrome Web Store. To view them, go to the Tools menu and select "Extensions". This will show you a list of all installed Chrome extensions and apps.
To learn more about extension development, see the Getting Started Tutorial.
Also, as someone else mentioned, you're using the Skype Call Extension. However, an app using that directory name doesn't appear in the first page of the search results. It might be worth doing some more research to make sure you got that extension from a legitimate source, whether that be Skype or the Chrome Web Store.
If you're seeing it in Chrome developer tools for every request you make, it means it has access to all your websites, which could be benign, like if they're just making phone numbers clickable, or it could be malicious, if it's scraping your bank account info and shipping it off to some third party server. :)
It's a Chrome extension, and chrome-extension:// is a URL for extensions to address their contents via Javascript.
lifbcibllhkdhoafpjfnlhfpfgnpldfl is the unique identifier for the extension. I can't find it with a search, but apparently it might be Skype.
It's not pretending... it is a valid URL. The Javascript file is located in the extension. If you were to look on your harddrive you'd probably find that very file in the extensions folder.
The functions its calling probably are some sort of detection used by the extension to see if it needs to enable itself.
See this for some additional information:
Checking if user has a certain extension installed

Execute local command with JavaScript in Chrome

My mail client is configured to open links in mails with Chrome. But sometimes, when I get a mail from our ticket system, which doesn't work at all on Chrome, I'd like to open the link with internet explorer.
Therefore I tought a Javascript user script would probably do the job. I've searched, and there seems to be a way, with using ActiveX. Unfortunately this won't work in Chrome. Does anybody know how I'd go about that? Is there some kind of plugin or class which would allow me to do this kind of thing in Chrome? Or is there a another solution?
You could setup a custom protocol handler on your system.
For example, you could use a protocol in your html like this:
I get opened in IE
Then you register sd as a protocol, and tell Windows to open those kind of links with IE
Registering an Application to a URL Protocol
http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
ISSUE:
Looks like it passes in the protocol part, so IE wouldn't know what to do with that. You could write a very simple batch file to strip the protocol part, and then launch IE.
Here is an example batch file:
#echo off
set a=%1
start "" "c:\program files (x86)\internet explorer\iexplore.exe" %a:~3%
It creates a variable "a" that it sets to the first parameter "%1"
then its starts iexplore, stripping off the first 3 characters of "a"
There's not an easy solution. Any solution you could find for this would be pretty hacky as javascript is not designed to do this. The only solution I can think of is to use a chrome extension to launch an external application based on the url of the page visited, but I don't know if chrome extensions even have that capability.
Not sure how helpful it will be, but the chrome extension tutorial page might contain something useful.

Categories

Resources