-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Keep background Browser WebViews automatable #6027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3397,6 +3397,7 @@ final class BrowserPanel: Panel, ObservableObject { | |
| private var backgroundPreloadWindow: NSWindow? | ||
| private let visualAutomationCaptureGate = BrowserScreenshotCaptureGate() | ||
| private var activeVisualAutomationCaptureCount: Int = 0 | ||
| private var webViewLastAutomationActivityAt: Date? | ||
| private struct PendingInteractiveBrowserPrompt { | ||
| let present: (NSWindow, @escaping () -> Void) -> Void | ||
| let cancel: () -> Void | ||
|
|
@@ -3788,6 +3789,7 @@ final class BrowserPanel: Panel, ObservableObject { | |
| webViewLastHiddenAt = nil | ||
| webViewLastVisibilityChangeAt = nil | ||
| webViewLastVisibilityChangeReason = nil | ||
| webViewLastAutomationActivityAt = nil | ||
| isWebViewVisibleInUI = false | ||
| } | ||
| hiddenWebViewDiscardManager.resetMetadata() | ||
|
|
@@ -6395,6 +6397,10 @@ extension BrowserPanel: BrowserHiddenWebViewDiscardManagerDelegate { | |
| webViewLastHiddenAt | ||
| } | ||
|
|
||
| var hiddenWebViewDiscardLastAutomationActivityAt: Date? { | ||
| webViewLastAutomationActivityAt | ||
| } | ||
|
|
||
| var hiddenWebViewDiscardWebViewInstanceID: UUID { | ||
| webViewInstanceID | ||
| } | ||
|
|
@@ -7580,6 +7586,34 @@ extension BrowserPanel { | |
| } | ||
| } | ||
|
|
||
| @discardableResult | ||
| func beginAutomationCommandLease(reason: String) -> BrowserScreenshotWebViewSnapshotter.OffscreenRenderHostLease? { | ||
| webViewLastAutomationActivityAt = Date() | ||
| activeVisualAutomationCaptureCount += 1 | ||
| cancelHiddenWebViewDiscard() | ||
| restoreDiscardedWebViewIfNeeded(reason: "\(reason).restore") | ||
| refreshWebViewLifecycleState() | ||
|
|
||
| guard shouldUseOffscreenRenderHostForVisualAutomation else { return nil } | ||
| return BrowserScreenshotWebViewSnapshotter.OffscreenRenderHostLease( | ||
| webView: webView, | ||
| viewportSize: visualAutomationViewportSize() | ||
| ) | ||
| } | ||
|
|
||
| func endAutomationCommandLease( | ||
| _ lease: BrowserScreenshotWebViewSnapshotter.OffscreenRenderHostLease?, | ||
| reason: String | ||
| ) { | ||
| lease?.end() | ||
| webViewLastAutomationActivityAt = Date() | ||
| activeVisualAutomationCaptureCount = max(0, activeVisualAutomationCaptureCount - 1) | ||
| refreshWebViewLifecycleState() | ||
| if activeVisualAutomationCaptureCount == 0, !isWebViewVisibleInUI { | ||
| scheduleHiddenWebViewDiscardIfNeeded(reason: "\(reason).finished") | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lease ends during active captureMedium Severity
Reviewed by Cursor Bugbot for commit e3fd55b. Configure here. |
||
|
|
||
| @discardableResult | ||
| func ensureVisualAutomationRestoreHostIfNeeded(reason: String) -> Bool { | ||
| guard shouldUseOffscreenRenderHostForVisualAutomation else { return false } | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.