0

I am trying to pause all tab's execution using Chrome DevTools protocol. For that I iterate over all the tabs to get the CDP client for each tab and then send a request to pause JS on every tab. I see it resolve for some tabs properly but not all of them. Any reason this would be happening?

Code that I am using to pause and wait for paused event to get fired:

await client.send(`Debugger.enable`)
new Promise(resolve => {
  client.on(`Debugger.paused`, resolve)
  client.send(`Debugger.pause`),
})

Vikram Tiwari
  • 3,615
  • 1
  • 29
  • 39
  • `Promise.all` runs everything in parallel. So, some things may run/complete before your `client.on` is been registered. – mwilson Sep 24 '20 at 18:50
  • Good catch @mwilson. I have updated the code (in question as well) but I am still seeing some tabs not getting resolved. – Vikram Tiwari Sep 24 '20 at 18:58
  • I ran some tests on my side and I think it might be because the pages aren't executing any JS code after the call to pause JS has been made. As soon as I go to those pages and cause them to render, the `paused` event is thrown and JS execution is paused. An example of this is playwright.dev which doesn't do any background processing and if that tab is in background then `paused` event is not received from this page. – Vikram Tiwari Sep 24 '20 at 19:28

1 Answers1

0

As answered by Pavel Feldman on PlayWright slack: You can only pause in JS upon a stack guard. So if there is no JS running, there is no pause. To pause just issue a Runtime.evaluate after you issue pause.

Code that works on all types of pages:

await client.send(`Debugger.enable`)
new Promise(resolve => {
  client.once(`Debugger.paused`, resolve)
  client.send(`Debugger.pause`)
  client.send(`Runtime.evaluate`, {expression: ``})
})
Vikram Tiwari
  • 3,615
  • 1
  • 29
  • 39