Context manager executes ``page.enable()`` when it enters and then calls ``page.disable()`` when it exits. This keeps track of concurrent callers and only disables page events when all callers have exited.
(self)
| 368 | |
| 369 | @asynccontextmanager |
| 370 | async def page_enable(self): |
| 371 | """Context manager executes ``page.enable()`` when it enters and then calls ``page.disable()`` when it exits. |
| 372 | |
| 373 | This keeps track of concurrent callers and only disables page |
| 374 | events when all callers have exited. |
| 375 | """ |
| 376 | global devtools |
| 377 | async with self._page_enable_lock: |
| 378 | self._page_enable_count += 1 |
| 379 | if self._page_enable_count == 1: |
| 380 | await self.execute(devtools.page.enable()) |
| 381 | |
| 382 | yield |
| 383 | |
| 384 | async with self._page_enable_lock: |
| 385 | self._page_enable_count -= 1 |
| 386 | if self._page_enable_count == 0: |
| 387 | await self.execute(devtools.page.disable()) |
| 388 | |
| 389 | |
| 390 | class CdpConnection(CdpBase, trio.abc.AsyncResource): |