Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop scripts execution on the page?

I have a random internet page opened in my Chrome. I'm opening it with enabled javascript as I need some scripts to be executed.

Than from some moment I want to stop script execution, so no any timers or event handlers should be run. Of couse using an infinite loop is not ok as I want the page to be responsive.

How can I achive that?

Following code partially does what I need

document.body.outerHTML = document.body.outerHTML
for(t=setTimeout(()=>{}); t; --t) clearTimeout(t)

but:

  1. Event listeners on document and ajax callbacks will survive
  2. This causes parsing html, so some invalid markup can be changed by parsing

Also I hope there is some way to do it via devtools without actually interacting with page's code.

PS: If I need to use other browser, that's ok.

like image 867
Qwertiy Avatar asked Feb 28 '17 20:02

Qwertiy


2 Answers

You can enable/disable JavaScript on the page at any point using the command menu in DevTools. You can access this menu by using Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux).

Start typing Disable JavaScript and hit Enter to disable script execution.

In the following example, I ran an asynchronous timer to log an incremental count every 500ms. Upon disabling JavaScript, the execution was paused and nothing else logged to the console.

Disable

I later re-enabled JavaScript by typing 'Enable JavaScript` and hitting Enter. Upon doing this, the execution continued and the timer continued where it left off.

Paused

Note: Any synchronous code still running when you try to disable JavaScript won't be killed. It will finish and then further execution will be disabled.

like image 199
Gideon Pyzer Avatar answered Oct 16 '22 07:10

Gideon Pyzer


Adding to Gideon Pyzer:

Shift-Ctrl-I - wait for devTools to open,
then Shift-Ctrl-P - if you don't wait: print dialog will open...
then -see Gideon Pyzer's answer-.

like image 32
iAmOren Avatar answered Oct 16 '22 06:10

iAmOren