How can Greasemonkey transfer data securely?

646 Views Asked by At

I want to collect some data inside a user-area of a particular page and send this data to my web server.

As this data holds private financial information, the transfer should be secured.

How can I send the data securely using Greasemonkey or Tampermonkey?

1

There are 1 best solutions below

1
Brock Adams On BEST ANSWER

To transmit data securely from a Greasemonkey/Tampermonkey script, use GM_xmlhttpRequest() to POST data to your secure server.
Use SSL (https://) to do so.

For example:

// ==UserScript==
// @name     _Demonstrate secure data transmission
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant    GM_xmlhttpRequest
// ==/UserScript==

var secureStr_1 = "Don't let anybody see this!",
    secureStr_2 = "The Super secret borscht recipe is...";

GM_xmlhttpRequest ( {
    method:     "POST",
    url:        "https://YOUR_**SECURE**_SERVER.COM/YOUR_SAVE_PATH/",
    data:       "secureStr_1=" + encodeURIComponent (secureStr_1)
                + "&" + "secureStr_2=" + encodeURIComponent (secureStr_2)
                // etc.
                ,
    headers:    {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    onload:     function (response) {
        console.log (response.responseText);
    }
} );