Athlon1600/php-proxy

XMLHttpRequest is not proxified

Closed this issue · 3 comments

Requests sent using JavaScript's XMLHttpRequest do not get proxified and therefore do not work.

I have made a little JS script which redirects all Requests. It doesn't matter if from XHR or fetch

request.js.php

<?php
include dirname(__DIR__)."/conf.php";
header("Content-Type: application/javascript");
?>
(function() {
	let proxy = "<?php echo $config["baseURL"]; ?>?q=";

	let open = XMLHttpRequest.prototype.open;
	XMLHttpRequest.prototype.open = function(...args) {
		args[1] = proxy + encodeURIComponent(args[1]);
		open.call(this, ...args);
	};

	let fetch = window.fetch;
	window.fetch = function(url, ...args) {
		if(typeof url == "object") {
			url.url = proxy + encodeURIComponent(url.url);
		} else {
			url = proxy + encodeURIComponent(url);
		}
		fetch.call(this, url, ...args);
	}
})();

Thank you, however there is also another issue where many websites don't work as assets (mostly JS files) are loaded dynamically. Is there any way to circumvent this? I might have an idea, but I'm not 100% sure.

I am right now building a newer web proxy nammed cUPP and have also an idea.

I want to use a regex to filter all URLs and use a base to redirect relative ones.