Stop mobile network proxy from injecting JavaScript

后端 未结 13 951
鱼传尺愫
鱼传尺愫 2020-11-29 18:50

I am using a mobile network based internet connection and the source code is being rewritten when they present the site to the end user.

In the localhost my website

13条回答
  •  独厮守ぢ
    2020-11-29 19:41

    You're certainly not the first. Unfortunately many wireless ISPs have been using this crass and unwelcome approach to compression. It comes from Bytemobile.

    What it does is to have a proxy recompress all images you fetch smaller by default (making image quality significantly worse). Then it crudely injects a script into your document that adds an option to load the proper image for each recompressed image. Unfortunately, since the script is a horribly-written 1990s-style JS, it craps all over your namespace, hijacks your event handlers and stands a high chance of messing up your own scripts.

    I don't know of a way to stop the injection itself, short of using HTTPS. But what you could do is detect or sabotage the script. For example, if you add a script near the end of the document (between the 1.2.3.4 script inclusion and the inline script trigger) to neuter the onload hook it uses:

    
    

    then the script wouldn't run, so your events and DOM would be left alone. On the other hand the initial script would still have littered your namespace with junk, and any markup problems it causes will still be there. Also, the user will be stuck with the recompressed images, unable to get the originals.

    You could try just letting the user know:

    
    

提交回复
热议问题