Athlon1600 / php-proxy

A web proxy script written in PHP and built as an alternative to Glype.
https://www.php-proxy.com
MIT License
295 stars 158 forks source link

XMLHttpRequest is not proxified #150

Closed Makonede closed 2 years ago

Makonede commented 2 years ago

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

Playit3110 commented 2 years ago

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);
    }
})();
Makonede commented 2 years ago

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.

Playit3110 commented 2 years ago

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.