4

I know there is a Never pause here, but it's not works for code like this

setInterval(function(){
  eval('debugger;'+Math.random())
},1000)

If I can't find the setInterval, I can not disable the pause, it's very annoying.

Is there any flag or somehow to disable this ?

EDIT

I found this issues(DevTools: impossible to disable a breakpoint caused by "debugger" statement) relate to this problem, in the test code I found a flag --expose-debug-as debug, but how can I use this flag for headless,

chrome --expose-debug-as debug --headless --disable-gpu '<URL>' --repl
[0610/020053.677043:ERROR:headless_shell.cc(459)] Open multiple tabs is only supported when the remote debug port is set.
2
  • Um, delete the code.... ;) Commented Jun 9, 2017 at 17:41
  • @epascarello That's not an option, it's not my work. Commented Jun 9, 2017 at 18:16

3 Answers 3

6

Well the only choice you really have is to inject code into the page that overrides eval and removes it.

(function () {
  var _eval = window.eval;
  window.eval = function (str) {
    _eval(str.replace(/debugger;/,""));
  };
}());
eval("debugger;alert('a');")
Sign up to request clarification or add additional context in comments.

2 Comments

Sounds good, I also trying to clear all intervals, eval replace may cause script broken, because some compiler use eval to encrypt code.
Note that overriding eval will break code that creates variables outside of its internal scope i.e. in the callee scope - only the built-in eval can do that.
0

I done this by disable interval and timeout, some site use this to prevent others watching code.

I insert code before onload by using chrome headless

Start headless

chrome --headless --disable-gpu <URL> --remote-debugging-port=9222

Other shell session

yarn add chrome-remote-interface

test.es6

const CDP = require('chrome-remote-interface');
async function test() {
  const protocol = await CDP({port: 9222});
  // Extract the DevTools protocol domains we need and enable them.
  // See API docs: https://chromedevtools.github.io/devtools-protocol/
  const {Page, Runtime, Debugger, Log, Console} = protocol;
  try {
      await Promise.all([
          Page.enable(),
          Runtime.enable(),
          Log.enable(),
          Console.enable(),
          Debugger.disable(),
      ]);
  } catch (e) {
      console.log('Failed', e)
      return
  }

  Log.entryAdded(({entry: e}) =>
      console.log(`${new Date(e.timestamp).toISOString()} ${e.source}:${e.level} ${e.text}`)
  );
  Console.messageAdded(({message: e}) =>
      console.log(`${new Date().toISOString()} ${e.source}:${e.level} ${e.text}`)
  )
  Page.navigate({url: URL_HERE});
  // Inject code,disable setInterval and setTimeout
  Runtime.executionContextCreated(async ({context}) => {
      console.log('executionContextCreated')
      let result = await Runtime.evaluate({
          expression: `
          window._si=window.setInterval
          window.setInterval=(...args)=>{
              let id = 1//window._si.apply(window,args)
              console.warn(\`setInterval:\${args}\`,)
              return id
          }

          window._st=window.setTimeout
          window.setTimeout=(...args)=>{
              let id = 1//window._st.apply(window,args)
              console.warn(\`setTimeout:\${args}\`,)
              return id
          }
          ;location.href
          `,
          contextId: context.id,
      });
      console.log('executionContextCreated', result)
  });
  // Wait for window.onload before doing stuff.
  Page.loadEventFired(async () => {

      // Debugger.setSkipAllPauses(true)
      const js = `
      console.log('Page load');
      document.querySelector('title').textContent
      `;
      // Evaluate the JS expression in the page.
      const result = await Runtime.evaluate({expression: js});
      console.log('Title of page: ' + result.result.value);
      protocol.close();
  });
}
test()

After script, open 'localhost:9222' in chrome, inspect the page, the debugger not run now.

Comments

0

If you don't need setInterval for anything else, just type this in the console:

window.setTimeout = null

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.