So I'm trying to POST the URLs I visit in my browser(Firefox) to my Node-red instance on the same machine.
I set up a very simple flow with an "HTTP in" node to grab them:
[{"id":"74ec266a4dce6944","type":"http in","z":"1540ac82c636ea50","name":"","url":"/firefox","method":"post","upload":false,"swaggerDoc":"","x":190,"y":200,"wires":[["5f8f7eb0e6d819a0","11d8ea58f48f31b6"]]},{"id":"14c08e65804dea2a","type":"http response","z":"1540ac82c636ea50","name":"","statusCode":"","headers":{},"x":610,"y":200,"wires":[]},{"id":"5f8f7eb0e6d819a0","type":"debug","z":"1540ac82c636ea50","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":410,"y":160,"wires":[]},{"id":"11d8ea58f48f31b6","type":"change","z":"1540ac82c636ea50","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"success","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":200,"wires":[["14c08e65804dea2a"]]}]
It works okay for most pages, other than YouTube. I believe this is because the way YouTube page script intercepts changes to the URL (as long as they're within the same domain) and uses a View Router to re-render the page with the new details, including making requests for new data.
The userscript I've made only seems to throw one error in the Web Dev Console:
Error: Promised response from onMessage listener went out of scope
The userscript code is:
var address = location.href;
(function() {
'use strict';
function GetURL() {
let requestOptions = {
method: "POST",
url: "http://192.168.50.224:6969/firefox",
data: `${address}`,
headers: {
"Content-Type": "application/javascript"
},
onload: function track() {
console.log(`Successfully logged ${address}.`);
}
};
GM_xmlhttpRequest(requestOptions)
};
GetURL();
let mutationObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (address != document.location.href) {
address = document.location.href;
GetURL();
return true;
}
});
});
if (document.querySelector("#movie_player") !== null) {
mutationObserver.observe(document.querySelector("#movie_player"), {
attributes: false,
characterData: false,
childList: true,
subtree: true,
attributeOldValue: false,
characterDataOldValue: false
});
}
})();
I can't seem to figure out the fix, any ideas?