Detect if user have my Chrome extension installed? - javascript

I started to work on a very cool Chrome extension and I ran into a little problem.
I want to allow my user to share a link. By sharing this link, other users can get some information with my extension.
The problem is when a user click on the shared link, I want to check if my Chrome extension is installed on his browser. If it does - great, else - I want to redirect him to download my extension.
Any ideas how to?

One possibility is to have your extension run a content script on all sites* and add a listener for click events on document. It would check event.target to make sure it's a link and has a particular prefix, and if it does, it would call the preventDefault method of its parameter and do its stuff. For users without your extension, the link would of course work like any other.
*This causes Chrome to warn your potential users about this when they install your extension; read Permission Warnings for more information.

Make the extension add an invisible element to the DOM of every page that it loads, marking it with a unique ID. When the user clicks on that link, run some javascript to check for that element -- if it doesn't exist, then you know the extension hasn't been installed.

I think you should be able to set/modify headers in the HTTP requests (as of Chrome 17?). Adding a header to requests would mean you can detect the presence of the extension on the server side.
This is fairly unintrusive. Many extensions/plugins have historically modified the User-Agent header.

Related

Detect supported protocols in browser

I have a web page, where i would like to add links using a custom protocol, to open in my desktop application. For example "myprotocol:www.mytestpage.com".
My issue is, how do I detect, using javascript, if the user has registered my protocol?
If for example I use the link above in firefox, withouth having the protocol registered, I am just taken to an error page. Instead I want to show a dialog telling the user to download my application.
As far as I know you cannot tell whether the protocol has been registered or not.
This answer should give you a step in the right direction. https://stackoverflow.com/a/24129863/7326037

Open devTools in chrome, and select "Network", click "XHR", and there are extra information in any page [duplicate]

When I'm viewing the downloaded resources for a page in the Chrome web inspector, I also see the HTML/JS/CSS requested by certain extensions.
In the example above, indicator.html, indicator.js and indicator.css are actually part of the Readability Chrome extension, not part of my app.
This isn't too big a deal in this particular situation, but on a more complex page and with several extensions installed, it can get quite crowded in there!
I was wondering if there was a way to filter out any extension-related resources from this list (i.e. any requests using the chrome-extension:// protocol).
Does anyone know how I could achieve this?
Not quite the solution I was after (I'd have preferred a global setting), but there is now a way to filter out requests from extensions, as mentioned by a commenter on the issue I originally opened.
In the network tab filter box, enter the string -scheme:chrome-extension (as shown below):
This is case-sensitive, so make sure it's lowercase. Doing this will hide all resources which were requested by extensions.
Just enter "-f" in Network field
Was having the same question when my extension adds a lot of noise in the network tab.
Some extensions also fire a lot of data like data:text/image etc, you can append more filter with - like:
-scheme:chrome-extension -scheme:data
Another way to get the http/https requests is to just use scheme:https without - because the resources that extensions request are usually from their local bundle:
scheme:https
An Incognito Window, can be configured to include or exclude extensions from the extensions page of Chrome settings.
One alternative is to go to "Network Request blocking" tab and add "chrome-extension:" to the list, thus extension requests will be blocked and coloured red so it's easy to visually filter them out.
you can simply enable this option and requests from extension will be group.
Update: It can only group requests that create by the extension that draw iframe, such as cVim

Can a chrome extension be opened when requesting specific external protocol?

I want to write a chrome extension that is triggered when the browser redirect to a specific external protocol: myApp://...
I googled a bit and didn't find an easy meta-data way to do so.
is there a way to define it in the manifest?
I want the extension to open a popup then, and I'll wait for it in my automation testing.
You can, in theory, use a protocol handler with navigator.registerProtocolHandler, but there are limitations:
Custom protocols must start with web+ in Chrome, e.g. web+myApp:
There is no way to declare this in a manifest; according to this feature request to add that possibility, currently it will pop up an allow/deny infobar for the user.
In any case, opening a popup programmatically is impossible. At most you can open an extension page in a tab.

Can I use javascript to add a bookmark that is not a http url?

I have this bookmarklet, i.e. it does not start with 'http:' but with 'javascript:'. No issue with that, it works correctly.
The problem occurs when I want to deploy this to users. I'd like to present them a link they'll just click to add to their favorites. Whatever methods I use (examples found on the web, or JQuery with jFav), I end up with a javascript error 'permission denied' when clicking the link, though it works perfectly when the link to bookmark is a classic 'http' one.
I believe that's some security in browsers, but is there a way to avoid this?
It is indeed a security measure. If a user could be tricked into bookmarking and running a javascript: URL, that's pretty much global cross-site-scripting.
About all you can do is present the user with a javascript: link, and ask them to bookmark it via right-click-bookmark or drag-to-bookmarks. You should also write the link out so it can be copy-and-pasted and manually bookmarked, because some browsers won't present right-click-bookmark for a JavaScript link, and others may not have a bookmarks bar visible.
You can ask your users to drag and drop the bookmarklet to the their bookmarks or toolbar.

Display popup without security warning

I use Silverlight and I'm trying to get some data to the user side. I can easily display PDF file with an <embed> tag in the browser.
However, I also have to be able to save files form the server. I tried the SaveFileDialog from Silvelright but it doesn't allow setting the file name (which is an issue).
I tried setting a hidden <iframe> source to the URL from the server but that triggers a security warning and it's not good either (there would be too many clueless users calling because it doesn't work).
I tried calling window.open to trigger a new popup set to the URL. That works OK but again there's a security warning.
Is it possible to get rid of that security message? I know it's possible in Javascript.
An exampel is on the site
http://livetecs.com
(go to the live demo, then project manager and open a report in a new window: no security warning!)
How do they achieve that behavior?
If there's any other way to get my reports saved Silverlight I'd be very interested to hear about them.
EDIT: The warning I'm talking about is the Pop-up blocked. To see this pop-up or additional options click here.. banner appearing on top of the page.
Cheers.
There is no way around the pop up blocker when you open up a window without a user action. If there was a way around that, than the pop up blockers would be useless.
Only way to avoid the security message is to have the users add your site to their safe list.
OK, after much fiddling I came accross the Silverlight built-in pop-up window that I couldn't use before.
The only limitation is that it can only be triggered by a user action (which is fine in this context() PopUpWindow at MSDN
It fits the bill perfectly and I couldn't use it before because I wanted to pre-generate the report files before opening the pop-up (and thus I wasn't in a user event context anymore).
I'm going to create a report generation page that will display a status message and then show the report (I haven't worked out yet how I'll do that though).

Categories