简体   繁体   中英

How to inject a piece of JS code into an 3rd party web page?

I am trying to do some POC of client side utilities for a 3rd party web page. I want to inject a piece of my experimental JS into that page. But I don't have access to the target page. Is there any way to do it?

ADD 1

Ideally, I want to do it with IE 10. And I want to place the JS file locally on my disk, and have it loaded automatically.

ADD 2

Just found one related thread: Injecting JavaScript into head element of website using Fiddler

Maybe I didn't describe my question clear enough so many people think this cannot be done.

Inspired by this thread: Injecting JavaScript into head element of website using Fiddler , it turns out I can use FiddlerScript to achieve this.

Steps are:

  1. Set the oSession.bBufferResponse = true; in OnBeforeRequest() method so Fiddler proxy has a chance to buffer and modify the response.

  2. Then modify the response as I want in OnBeforeResponse() method, where I can inject my JS into the response DOM.

For details: check the book < Debugging with Fiddler > by Eric Lawrence, chapter ' FiddlerScript '

只需使用源创建一个新的 html 文档,然后添加您想要的所有 javascript。

Try to imagine what will happen if this would be possible.

And I think this is the answer to your question. This is mych more complicated / server / hardware / software / psychology / multi / complicated problem. Of course, sometimes there are a few possibilities to do it, but they are non universal / security holes cases.

Best regards!

BTW: But I don't have access to the target page. I assumed that you do not have access to the server too. As one implies another. If I'm mistaken, please update your question with more data.

Might be a little late but you can use Charles Proxy to do this and using the Rewrite feature you can place some code in there. I'm doing this for testing Google tag manager on some sites that don't belong to me :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM