Intercept an HTTP request at browser end to alter some html content

后端 未结 11 1699
灰色年华
灰色年华 2021-02-06 19:43

I would like to do as follows. What would be the best way? A general answer will also be fine.

I would like to intercept an HTTP request at the client end to alter some

相关标签:
11条回答
  • 2021-02-06 20:04

    Taken from here.

    It can be done via a Layered Service Provider on Windows.

    From Wikipedia:

    "A Layered Service Provider (LSP) is a feature of the Microsoft Windows Winsock 2 Service Provider Interface (SPI). A Layered Service Provider is a DLL that uses Winsock APIs to insert itself into the TCP/IP stack. Once in the stack, a Layered Service Provider can intercept and modify inbound and outbound Internet traffic. It allows processing all the TCP/IP traffic taking place between the Internet and the applications that are accessing the Internet (such as a web browser, the email client, etc). "

    AdMuncher for example is intercepting and inserting http code to avoid ads. Another suggestion is to find an open-source ad blocking program and see how they've implemented it.

    0 讨论(0)
  • 2021-02-06 20:10

    A long time ago I've implemented this feature for IE using Plugable Mime Filters so after I've searched about it in c# here in stackoverflow I've founded this post that should help you start with it.

    Hope this is useful for you.

    0 讨论(0)
  • 2021-02-06 20:11

    You can do this with Privoxy via their filter files. Their fun filter is a good example of exactly the sort of substitutions you want to do.

    To replace "Two LA Dogs Marry" with "Ridiculous Title Blocked" on cnn.com your action file would look something like this:

    { +filter{ridiculous-title-censor} }  
    .cnn.com
    

    and your filter file would look like

    # FILTER: ridiculous-title-censor Remove ridiculous titles
    # This keeps CNN from getting too ridiculous
    #
    s/Two LA Dogs Marry/Ridiculous Title Blocked/ig
    
    0 讨论(0)
  • 2021-02-06 20:12

    you can come to China ^_^ censorship like this is everywhere, you don't have to implement your own.

    Ok, that is a joke, the answer is you can implement browser plugins for such kind of tasks. or maybe you need to implement a ROUTING filter ( GFW like ) on the router.

    0 讨论(0)
  • 2021-02-06 20:14

    Another option if you're using Firefox is to use Greasemonkey scripts. Here's an example script which changes the main headline on cnn.com

    If you're not familar with the Javascript coding needed to make Greasemoney scripts, you can use the Platypus add-on to edit the page in place and automatically generate a script file.

    0 讨论(0)
提交回复
热议问题