Reputation: 7740
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.
Upvotes: 3
Views: 5692
Reputation: 868
If you don't need setInterval for anything else, just type this in the console:
window.setTimeout = null
Upvotes: 0
Reputation: 7740
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.
Upvotes: 0
Reputation: 207501
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');")
Upvotes: 5