Fix download_video KeyError, eliminate CDP stutter, and fix 0-byte WebM bug#28
Open
MuhammadSamarShehzad wants to merge 1 commit into
Open
Fix download_video KeyError, eliminate CDP stutter, and fix 0-byte WebM bug#28MuhammadSamarShehzad wants to merge 1 commit into
MuhammadSamarShehzad wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR resolves several critical bugs and significantly improves the performance and reliability of the
Element.download_video()method inbotasaurus_driver.1. Fixed Python
.format()KeyError crashIssue: The raw JavaScript payload string contained single curly braces
{}around the JS functions. When Python called.format(filename=..., duration=...)on it, it attempted to parse the JS braces as python format variables, throwing aKeyError.Fix: Escaped all JavaScript syntax braces to double braces
{{and}}, leaving only{filename}and{duration}for the Python formatter.2. Eliminated 3-Second Playback Stutter (CDP Latency)
Issue: Previously,
download_video()paused the video, injected theMediaRecordersetup, and resumed the video using three separate, sequential Pythonself.apply()CDP calls. The network round-trips caused the user's browser video to visibly stutter and freeze for 2–3 seconds.Fix: Consolidated the logic into a single JS execution block. The
vid.pause()andvid.play()are now executed entirely client-side. This makes the capture transition instantaneous and completely invisible to the user.3. Fixed Chrome
captureStream()0-Byte Empty Frame BugIssue: It is a known Chrome bug that calling
captureStream()on an HTML5 video that is actively playing can result in a dead stream with zero frames (resulting in 0-byte corrupted downloads).Fix: Added a synchronous bypass inside the JS payload:
vid.pause()->vid.captureStream()->vid.play(). By doing this synchronously in Javascript, we bypass the Chrome bug and guarantee frame capture without interrupting playback.4. Added Native MP4 Container Support
Issue: The previous code passed invalid
MediaRecorderoptions ({audio:true, video:true}) and forced a.mp4file extension on a genericoctet/streamblob. In Chrome, this defaults to a WebM container, which causes "Video Error" playback failures on macOS QuickTime when mislabeled as an MP4.Fix: Removed the invalid options and added dynamic
MediaRecorder.isTypeSupported('video/mp4')detection. Chrome M107+ natively supports MP4 encoding; if available, it will now encode a true MP4 container. Otherwise, it safely falls back to standard WebM.Testing:
botasaurusno longer crashes with aKeyErrorduringdownload_video.