I need to remap, from a single-page application client’s side, the request of several resources.

I can intercept the requests of resources that are loaded through fetch in this way

const {fetch: originalFetch} = window;

window.fetch = async (...args) => 
{
 let [resource, config ] = args;

 resource = resource.replace("www.somewhere", "www.elsewhere");
 const response = await originalFetch(resource, config);
 
 return response;
};

However, there’s a billion pieces of code where images (and video, and audio files for that matter) are loaded by simple assignment

var image = new Image();

image.onload = 
function()
{
 // something happens here
}

image.src = "www.somewhere.com/hello.jpg";

Is there any way to intercept assignments and operate on src before the actual request is processed?