Fix Chrome kill failure on Windows 11 by adding graceful error handling#111
Fix Chrome kill failure on Windows 11 by adding graceful error handling#111
Conversation
|
@lirantal 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
Co-authored-by: lirantal <316371+lirantal@users.noreply.github.com>
Co-authored-by: lirantal <316371+lirantal@users.noreply.github.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
|
🎉 This PR is included in version 1.14.11 🎉 The release is available on: Your semantic-release bot 📦🚀 |
User description
Fixed an issue where the application would crash on Windows 11 when trying to kill the Chrome process during cleanup. The error occurred when Chrome had already exited before the kill command was executed, causing
taskkillto fail with:Root Cause
The chrome-launcher dependency uses
taskkill /pid ${pid} /T /Fon Windows to terminate Chrome processes. However, when Chrome exits on its own (due to crashes, user intervention, or normal completion), the PID becomes invalid, causing the kill command to fail and bubble up as an unhandled error.Solution
Added graceful error handling around
chromeInstance.kill()insrc/Audit.js. When the kill operation fails, the error is caught and logged as a debug message instead of crashing the application. This approach recognizes that if Chrome is already dead, that's actually the desired outcome.Changes Made
src/Audit.js: WrappedchromeInstance.kill()in a try-catch block with debug logging__tests__/Audit.test.js: Added comprehensive test coverage for the error handling scenario and improved existing test mocksThe fix ensures that website vulnerability scans complete successfully even when Chrome cleanup encounters issues on Windows 11, while maintaining full backward compatibility and test coverage.
Fixes #110.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
PR Type
Bug fix
Description
Add graceful error handling for Chrome process termination failures
Prevent application crashes when Chrome exits before kill command
Improve test coverage with Chrome kill error scenarios
Fix Windows 11 specific taskkill command failures
Diagram Walkthrough
flowchart LR A["Chrome Launch"] --> B["Lighthouse Audit"] B --> C["Chrome Kill Attempt"] C --> D{"Kill Success?"} D -->|Yes| E["Clean Exit"] D -->|No| F["Log Debug Message"] F --> EFile Walkthrough
Audit.js
Add graceful Chrome kill error handlingsrc/Audit.js
chromeInstance.kill()in try-catch blockAudit.test.js
Enhance test coverage for Chrome kill errorstests/Audit.test.js
mockKillfunction for better test controlbeforeEachsetup with mock resetsnpm-shrinkwrap.json
Update package lock file metadatanpm-shrinkwrap.json