How to make my extension send data to me? - javascript

I am developing an extension that will allow the user to rate the page they are viewing. To do this, I want to capture their click ('Good' or 'Bad') from the extension popup and also the url of the site they are visiting.
I can capture both these data in JavaScript, but how do I immediately extract this data to my computer? Is there a way to use JS to capture these values in a bucket and load them to an existing XLS file on my machine?

All you need to do is have your extension make an AJAX request from the extension to your server. You'll need to ask for permission to allow the extension to access your server in the manifest.json file, as described in http://code.google.com/chrome/extensions/trunk/manifest.html#permissions
Once you receive the request on your server, you can do whatever you want with the data.

Related

Is that even feasable?: user click on a button on my website -> get data from another website -> display this data on my website

I tried to be the most explicit possible and I know I can do it in python but i'm trying to do it in javascript.
the data is in sms/tweet style and length so not very huge and I know where it's located on the other website
If the website you want to scrape is configured to allow cross-origin resource sharing (CORS), you can have the client scrape it.
Otherwise, your own server will have to perform the scraping then send it to the client.

Upload image from frontend and display it on user’s profile page

On my website I let registered members create multiple profiles, each of these with their own avatar picture.
On the Create Profile page, I have this input to submit the avatar...
... and get it displayed on the Profile page:
How can I recreate the same, uploading one more picture from Create Profile and display it on Profile page?
I know where the source files for each page are located, but unfortunately I’m unable to recreate it..
Thanks.
You need a 3 step process to upload the image file, store it and send it to the front-end users.
If your app is an SPA and you don't want to reload the page in the user's browser, you'll need a JS process to read the file from a file button and send it to your server (through AJAX as a FormData object for example)
Then your server should be able to handle the formdata object request and read file content from it. Once done, you have to save it in a secure server-side location.
Finally (again in case of an SPA) your server should be able to answer the picture data when the client asks it
The server should be able to give the avatar's URL when asked by the client (with a Restful API for example)
The server should be able to give access to the image when the client uses the image's url

How can I capture a file downloaded in an iframe?

I have an external site in an iframe with a save button. When the user clicks the save button a json file is downloaded, I would like to be able to capture the contents of this file in my own code. Is there any way to do this?
I read that you cannot specify a download location outside of the browser defined location, and could only find questions related to initiating a download with an iframe rather than capturing one.
You cannot do it unless you can setup the Access-Control-Allow-Origin (in HttpHeader) of your external site. (check out Access-Control-Allow-Origin on google)
There is a security reason to prevent user read data from other site without permission, for example, the user may logged in the bank site while browsing another site abc.com (in other tab), the bank will not allow abc.com download the users information from them by JavaScript.
If your project contains a server side, you could retrieve such data at server side and print out to client side.

Upload blob to dropbox from client-side javascript

I have an app that runs in the client browser and doesn't have any server side (http/js is served, but nothing posts to the server). the app is redeployed on many servers (iis, apache, nginx, sometimes localhost, sometimes on an intranet) and are served using http (not https). My app generates files such as zip files and pdf's in the clients browser as blobs BEFORE I want to save, so having them navigate away on the same page then back to the app defeats the purpose; and I can't post the generated data to dropbox anymore, since they have to start over... I want to be able to send these blobs directly to files in the end users dropbox (and later google drive).
https://www.dropbox.com/developers-v1/dropins/saver performs exactly as I would like. It pops up. It lets the user authenticate in the popup. It lets the user choose where they want to put my file. But I can't send it a data uri, or base64-encoded data, or a bytearray, or whatever. It only works with files previously saved somewhere accessible on the net. So it does not work for me.
https://www.newfangled.com/direct-javascript-dropbox-api-usage/ shows how I could embed the oauth data, which I don't have.
https://blogs.dropbox.com/developers/2013/12/writing-a-file-with-the-dropbox-javascript-sdk/ seems like it should work, except that it's trying to perform an oauth session and it uses the same window as my app (which is undesired).
My current tabs I'm looking at (includes entries from a few years ago, so things might have since changed). Some articles indicate that it isn't possible. Other articles incidate that it IS possible - i mean this particular comment https://github.com/dropbox/dropbox-js/issues/144# doesn't help me much. Neither does "I'll be sure to pass this along as feedback" - was it passed along? To whom?
https://github.com/dropbox/dropbox-js/issues/144
https://stackoverflow.com/questions/30094403/save-input-text-to-dropbox
https://blogs.dropbox.com/developers/2015/06/programmatically-saving-a-url-to-dropbox/
How can I upload files to dropbox using JavaScript?
upload file to dropBox using /files_put javascript
https://github.com/morrishopkins/DropBox-Uploader/blob/master/js/reader.js
https://www.dropbox.com/developers/saver
https://www.dropboxforum.com/hc/en-us/community/posts/202339309-Can-I-save-a-JSON-stream-object-to-Dropbox-file-with-Dropbox-Post-Rest-API-
https://github.com/smarx/othw
Can Dropbox Saver accept data from createObjectURL()?
It sounds like the code from https://blogs.dropbox.com/developers/2013/12/writing-a-file-with-the-dropbox-javascript-sdk/ works fine for you, but you want to do the auth in a separate browser window/tab.
If so, I'd suggest just changing that code to use the Popup auth driver instead.

Click ok or cancel of file download in JavaScript

Is there any way to detect if a user has selected ok or cancel to download a file in JavaScript? For instance if I have a link that points to a file and a user clicks on it download that will automatically start the download of the file, but how do I know if the user has been prompted to do download or not?
If they've clicked on it you can be pretty sure they'll be prompted to download it. To find out if they've downloaded it though, you'd need to implement that on the backend. There is no way the webpage itself will be able to know.
On the backend you'd have to monitor the communication with the client via the web server and see how much data has been transferred to the client and compare that with the total size of the file.
You could then make this data available on the server and using some sort of XMLHttpRequest or websocket, the page could update with a progress bar if that's what you're looking for.

Categories

Resources