Reputation: 23
I'm making an Ad Blocking program in Java.
In short I want my program to inject JavaScript into any webpage that is loaded, no matter what browser it is loaded in.
Bit more descriptive:
I'm trying to find a way to add JavaScript(blocks the ads) into a webpage, before its loaded.
I don't want my program to have a web browser in it, I want it to edit any webpage that is loaded, no matter what browser it is.
An example of what i'm trying to do is "ad muncher"
Upvotes: 1
Views: 182
Reputation: 1033
I think the best way to accomplish what you're trying to do is to set up your desktop application as a local proxy server. You would then be in a position to intercept all web traffic, parse each request as it comes in, and add/strip out whatever bits of code you are interested in. Keep in mind that in using this approach your users will have to configure their browsers to use your proxy server, and your code needs to be very fast so as not to slow down your user's browsing experience.
In order to make a proxy server you will need to know a bit about networking and about HTTP, I have always found Sun's (Oracle's) official Java Tutorials to be helpful when it comes to networking
Upvotes: 2
Reputation: 262644
It sounds like you need to make it work as a web proxy (like Privoxy for example), or something even lower-level on the networking stack. I don't think there is another way to hook into all web browsers. And this will most likely not work with HTTPS (which was specifically designed to prevent people on the wire from messing with the contents).
Upvotes: 1
Reputation: 5301
Not sure about the exact requirements but you can use Java filters, using filters you can modify content of any webpage before it reaches the client.
Some pointers are
Upvotes: 0