ChromeDevTools / debugger-protocol-viewer

DevTools Protocol API docs—its domains, methods, and events
https://chromedevtools.github.io/devtools-protocol/
Other
860 stars 173 forks source link

how can i intercept JS code before exectution in chrome #70

Closed wa-sunlab closed 7 years ago

wa-sunlab commented 7 years ago

Hi,

I would like to create chrome extension to dev tool where i would like to intercept JS code of current web page before it is compiled or executed by browser , Actually i want to instrument JS code before it to run in browser.

Can anybody will help us , how it is possible ?

Many Thanks in advance.

kdzwinel commented 7 years ago

Hey, thanks for reaching out. Unfortunately, this is not the right place to ask this question. Try SO: http://stackoverflow.com/questions/tagged/google-chrome-extension or ChromiumDev slack: https://chromiumdev-slack.herokuapp.com/?linkId=18742368

caspervonb commented 7 years ago

@wa-sunlab Ping me with a stackoverflow question and I'll elaborate.

Thinamajig.js instruments with a few simple steps. TLDR;

  1. Stop the document from loading with window.stop
  2. Fetch the document with XHR.
  3. Render scripts inert with a search and replace, e.g

    var html = request.responseText
     .replace(/type=\"text\/javascript\"/g, '')
     .replace(/<script/g, '<script type="live/javascript"');
  4. Write the processed HTML with document.write.
  5. Instrument and load the scripts.
wa-sunlab commented 7 years ago

@caspervonb http://stackoverflow.com/questions/40375167/how-can-i-intercept-js-code-before-exectution-in-chrome

wa-sunlab commented 7 years ago

@caspervonb Could you please explain me the step 3.

Many Thanks