How to intercept electron's request and return a customized response?


Suppose the user is able to play an audio on the electron app.

<audio id="audio" src="/resource/demo.mp3"></audio>

But the file /resource/demo.mp3 doesn’t exist. It’s just a URL, I want this request to be intercepted by electron’s rendering process, which would then extract demo.mp3 from a zip file and return it to the user, something like this:


const filter = "/resource/**"
electron.interceptRequest(filter, (url) => {
  const audio_name = url.split("/")[2]; // demo.mp3
  const audio_contents = extract_audio_contents_from_zip(audio_name);
  return audio_contents;

As you can see, it’s just like a controller in a web server, is it possible to do so in electron?