Is it possible to find out when a user installed a Chrome extension?
I know it's possible to save the date as local data when the user first uses the extension. I'm wondering if it's possible to get the date when the extension didn't store this data.
This is closest possible API: management, ExtensionInfo object.
Since it does not provide this information - no, this is not possible.
You can try different approach instead of requesting "management" permission from the users (they may reject the app only because this permission if it's not connection with application purpose). You can use chrome.storage (https://developer.chrome.com/extensions/storage) API in you background / event page. Both will run just after installation complete. Then you can read some flag using chrome.storage API and if it isn't set it means that the app has been installed a moment ago (the script will run just after installation finish). User can't delete this data so it is reliable. After installation just set the flag so it will not recognize installation again.
If you use background page you just need to call it anywhere in the file. If you use Event page you need to register an event chrome.runtime.onInstalled (https://developer.chrome.com/extensions/runtime#event-onInstalled).
Note that the onInstalled event is fired after app update or chrome update so you can't treat it as a one time registration event.
Related
I am creating a Chrome extension that tracks multiple events periodically such as the current date, the extension's install Id, etc. One particular event I want to keep track of is the browser's current default search engine. The extension has no popup so there is no user interaction.
That being said, the only way I can think of getting that information is from the browser's settings page. Is there any API or other logic I can use in JavaScript to achieve this?
I am currently trying to detect if a user has a certain Chrome extension installed. The Chrome extension is not my own and I do not have the source code to it. I have tried methods in numerous posts but they all fail. What I've tried and why it failed is detailed below.
This results in 'cannot read property connect of undefined' when executed:
var myPort=chrome.extension.connect('idldbjenlmipmpigmfamdlfifkkeaplc', some_object_to_send_on_connect);
Trying to load a resource of the extension as follows to test if it's there but going to this URL in browser results in 'your file was not found' Chrome error page (note that I found this path by going to C:\Users\\AppData\Local\Google\Chrome\User Data\Default\Extensions\idldbjenlmipmpigmfamdlfifkkeaplc\1.0.0.1_0\ on my Windows local machine):
chrome-extension://idldbjenlmipmpigmfamdlfifkkeaplc/1.0.0.1_0/icon_16.png
Using Chrome management but this results in console error 'cannot read property get of undefined' when executed
chrome.management.get("idldbjenlmipmpigmfamdlfifkkeaplc", function(a){console.log(a);});
And most other answers I've come across seem to involve the extension being written by the same person who is trying to check for it.
Assuming you need it from a website
connect/message method implies that the extension specifically listed your website in the list of origins it expects connection from. This is unlikely unless you wrote this extension yourself, as this cannot be a wildcard domain.
Referring to files within the extension from web context will return 404 simulate a network error unless the extension declared them as web-accessible. This used to work before 2012, but Google closed that as a fingerprinting method - now extensions have to explicitly list resources that can be accessed. The extension you specifically mention doesn't list any files as web-accessible, so this route is closed as well.
chrome.management is an extension API; websites cannot use it at all.
Lastly, if an extension has a content script that somehow modifies the DOM of your webpage, you may detect those changes. But it's not very reliable, as content scripts can change their logic. Again, in your specific case the extension listens to a DOM event, but does not anyhow make clear the event is received - so this route is closed.
Note that, in general, you cannot determine that content script code runs alongside yours, as it runs in an isolated context.
All in all, there is no magic solution to that problem. The extension has to cooperate to be discoverable, and you cannot bypass that.
Assuming you need it from another extension
Origins whitelisted for connect/message method default to all extensions; however, for this to work the target extension needs to listen to onConnectExternal or onMessageExternal event, which is not common.
Web-accessible resources have the same restrictions for access from other extensions, so the situation is not better.
Observing a page for changes with your own content script is possible, but again there may be no observable ones and you cannot rely on those changes being always the same.
Similar to extension-webpage interaction, content scripts from different extensions run in isolated context, so it's not possible to directly "catch"code being run.
chrome.management API from an extension is the only surefire way to detect a 3rd party extension being installed, but note that it requires "management" permission with its scary warnings.
I want to save full web page as a image or a pdf.
I tried to use html2canvas but it doesn't support iframe element.
I tried to use phantomjs but it doesn't work in Windows Server 2003 Operation System.
I usually use 360 browsers' plugin and Google Chrome's Full Page Screen Capture.
How can I call the Chrome plugins using JavaScript?
You can use Full Page Screen Capture extension.
Regarding calling this extension by javascript:
As far as I know the externally_connectable is the only official way to call an extension or send messages (maybe with data) from a web page (using javascript) as mentioned here.
If extension not support being externally_connectable, this requires editing the extension and add predefined values for every single domain you wish to integrate with.
If this is the case we can play with a workaround to integrate with any website (and not to define any domains)
If you just want to notify the other side (extension) about some thing, you can use the native JS Event dispatching it on the document from one side(web page) and listening to it at document also from the other side(extension) as the document is shared between the extension content script pages and the web page.
You can't use JS CustomEvent to send data as every time you send data, you receive it empty as a result of sandbox effect of any extension.
If you want to share data (may be the limit of scrolling when taking the screenshot) so the only workaround I know so far is to have a combination between some sort of a storage and the JS native Event mechanism.
The solution in steps (suppose you need the web page to call and send some data to the extension):
Make an event on document from the web page.
Save the data temporarily inside any storage technology you prefer
(localStorage, the DOM itself, or what ever..)
Edit the extension and add event listener to receive the event at the other side (extension) by listening on the document.
Read data and remove it.
Okay, this is a problem I have been having for sometime now, and I cant find a solution, Anywhere!
My Problem:
My HTML content is available as web application that can be used offline, but I want the contact form to also be available offline.
Is there anyway the user can fill in the contact form when they have no connection and then for a script to run that holds that inputted data until a connection is established.
And then once the connection is established for the data to be sent to a PHP script on a server?
Edit:
Thanks for all your answers! I have looked into local storage but this doesnt work as the user may revist the page but they still probably wont have an internet connection, so I was wondering if there is any type of script that can run locally all the time until there is an established internet connection
Thank you in advance!
You can not run a script unless the page is opened.
The only way around this would be to create a Chrome Extention or FireFox Addon:
http://en.wikipedia.org/wiki/Google_Chrome_Extensions
http://en.wikipedia.org/wiki/Add-on_(Mozilla)
Yes - provided that they open your page again with an internet connection at a later date.
The steps are:-
Try and send message (AJAX etc.)
If it fails due to no connection - store to localstorage.
Have a loop that checks for messages in local storage.
If message found try to re-send.
Once message is sent remove it from local storage. (AJAX success)
That is indeed possible if the website stays open.
You can have a javascript loop that checks some recource (i.e. a tiny json file on your server) and if it can read this successfully, it attempts to send the email/data.
If it is not, it waits for a certain time using timeout.
You'll surely be able to find examples of this on the internet since this is often used in modern web development due to the often unstable connection of smartphones.
you can try local storage to store the data and retrieve it after the browser re-opens Or cookies.
If you use mozilla you can hack the XUL codes and inject your scripts into it. Otherwise you must hack the browser template which supports js
I am using ExtJs for front end development and I am looking for a way to set the destination for a file to be downloaded. I know I can use xtype:filefield to browse files, but that requires me to select an actual file, I just need to select a folder for the file destination and then send that path elsewhere. Any way I can do that?
You will not be able to choose the user's download location with javascript. This can only be set from the user's end, otherwise it would violate user's security.
If your app is for an intranet only there are various ways you can push a config onto the user's browsers (depending on which web browser they are running in the intranet). But that would make ALL downloads go to that location.
Most browsers also have a configuration that allow the user to define a location for every download as covered here and here's more specifics for different browsers. The user would be able to (and have to) select the download location for every download.
If this is for an intranet app, and if your intranet is running Firefox, there is also this add-on. You would have to push it out to all your user's computers (or manually install it on them all). I haven't tried it yet but I was planning on using it should a situation like yours arise (all my ExtJS work is for an intranet running Firefox - I push out things like this using a logon script whenever a user logs into the network to automatically install them).