Created
February 6, 2026 19:07
-
-
Save k0pernikus/8a6d745fcaef8fce8e583a621dc90699 to your computer and use it in GitHub Desktop.
python playwright block page.pause
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import sys | |
| from pathlib import Path | |
| MAX_CONCURRENT_FILES = 5 | |
| def _analyze_file_content(filename: str) -> None: | |
| if Path(filename).name == Path(__file__).name: | |
| return | |
| try: | |
| content = Path(filename).read_text(encoding="utf-8") | |
| except UnicodeDecodeError: | |
| return | |
| if "page.pause()" not in content: | |
| return | |
| lines = content.splitlines() | |
| for i, line in enumerate(lines, start=1): | |
| if "page.pause()" in line: | |
| raise ValueError(f"COMMIT REJECTED: 'page.pause()' found:\n\033[1m{filename}:{i}\033[0m\n > {line.strip()}\n") | |
| async def _process_file(filename: str, semaphore: asyncio.Semaphore) -> None: | |
| loop = asyncio.get_running_loop() | |
| async with semaphore: | |
| await loop.run_in_executor(None, _analyze_file_content, filename) | |
| async def main() -> None: | |
| filenames = sys.argv[1:] | |
| if not filenames: | |
| return | |
| semaphore = asyncio.Semaphore(MAX_CONCURRENT_FILES) | |
| tasks = [asyncio.create_task(_process_file(f, semaphore)) for f in filenames] | |
| try: | |
| await asyncio.gather(*tasks) | |
| except ValueError as e: | |
| print(str(e)) | |
| for task in tasks: | |
| task.cancel() | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"Unexpected error: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment