I feel like this has a simple solution but the web has me running in circles, with a lot of conflicting information due to differences between manifest versions.
Basically, I just want the extension to grab any text/plain resource that is destined for the main_frame (i.e. not a xmlhttprequest) and prevent the browser from doing its default behavior of generating the <pre> content. Instead it should run the script content.js instead.
A minimal manifest.json that is working aside from not triggering at the right time is here:
{
"manifest_version": 3,
"name" : "text/plain interceptor",
"permissions":["storage","webRequest"],
"host_permissions":["<all_urls>"],
"content_scripts": [{"matches": ["<all_urls>"],"js": ["content.js"]}]
}
This works great, but it doesn't run until the browser first renders the entire text file into a <pre> tag, which gets quite slow for large files. And it's entirely unnecessary because I'm building the entire <html> doc from scratch and throwing away what the browser generates anyway.
So what magic is required to stop the browser from doing anything at all with the content, and just letting the extension deal with it?