mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
refactor(browser): import input and cookie types from defining owners
This commit is contained in:
@@ -14,9 +14,9 @@ import {
|
||||
import type { ResolvedBrowserCommandTarget } from '../session-routing/agent-browser-command-target'
|
||||
import {
|
||||
dispatchPageKeyEvents,
|
||||
routePageTextInsertion,
|
||||
type GuestCdpSender
|
||||
routePageTextInsertion
|
||||
} from '../../cdp/input/guest-direct-key-input'
|
||||
import type { GuestSessionCdpSender } from '../../cdp/input/guest-frame-input-sessions'
|
||||
import { assertExpectedPageUrlForStep } from '../../cdp/input/browser-expected-page-url'
|
||||
import { sendGuestCdpCommand } from '../../cdp/debugger/guest-cdp-command'
|
||||
import { AgentBrowserBridgeCaptureCommands } from './agent-browser-bridge-capture-commands'
|
||||
@@ -76,7 +76,7 @@ export abstract class AgentBrowserBridgeKeyCommands extends AgentBrowserBridgeCa
|
||||
try {
|
||||
releaseDebugger = acquireElectronDebugger(wc).release
|
||||
await this.waitForPagePaint(wc, target.webContentsId)
|
||||
const send: GuestCdpSender = (method, params, sessionId) =>
|
||||
const send: GuestSessionCdpSender = (method, params, sessionId) =>
|
||||
sendGuestCdpCommand(wc, method, params, sessionId)
|
||||
const guardFocus = (): Promise<() => void> =>
|
||||
this.browserManager.guardUserFocusForAgentInput(target.webContentsId)
|
||||
|
||||
@@ -12,9 +12,9 @@ import {
|
||||
import {
|
||||
dispatchPageKeyEvent,
|
||||
isEmbeddedGuest,
|
||||
routePageTextInsertion,
|
||||
type GuestCdpSender
|
||||
routePageTextInsertion
|
||||
} from '../input/guest-direct-key-input'
|
||||
import type { GuestSessionCdpSender } from '../input/guest-frame-input-sessions'
|
||||
import { withAgentInputInjection } from '../input/agent-input-injection'
|
||||
import type { AgentPointerInput } from '../../guest-lifecycle/page-activity/browser-agent-activity'
|
||||
import type { CapturePaintHold } from './cdp-screenshot'
|
||||
@@ -147,7 +147,7 @@ export class CdpPageInputCommands {
|
||||
)
|
||||
}
|
||||
|
||||
private readonly sendRoot: GuestCdpSender = (method, params, sessionId) =>
|
||||
private readonly sendRoot: GuestSessionCdpSender = (method, params, sessionId) =>
|
||||
this.debuggerChannel.sendDebuggerCommand(method, params, sessionId)
|
||||
|
||||
// Focus awaits must not reorder pipelined key, text, or pointer events.
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import type { WebContents } from 'electron'
|
||||
import type { CapturePaintHold } from '../commands/cdp-screenshot'
|
||||
import { isEmbeddedGuest, type GuestCdpSender } from '../input/guest-direct-key-input'
|
||||
import { readRecord, settleWithin } from '../input/guest-frame-input-sessions'
|
||||
import { isEmbeddedGuest } from '../input/guest-direct-key-input'
|
||||
import {
|
||||
readRecord,
|
||||
settleWithin,
|
||||
type GuestSessionCdpSender
|
||||
} from '../input/guest-frame-input-sessions'
|
||||
|
||||
const PAINTED_EXPRESSION = "performance.getEntriesByType('paint').length > 0"
|
||||
const AWAIT_FIRST_PAINT_EXPRESSION = `new Promise((resolve) => {
|
||||
@@ -14,7 +18,7 @@ const AWAIT_FIRST_PAINT_EXPRESSION = `new Promise((resolve) => {
|
||||
const gatedDocumentByGuest = new WeakMap<WebContents, number>()
|
||||
|
||||
// Answers the document to gate, or null. A failed or timed-out probe means a busy page.
|
||||
async function unpaintedDocument(send: GuestCdpSender): Promise<number | null> {
|
||||
async function unpaintedDocument(send: GuestSessionCdpSender): Promise<number | null> {
|
||||
const response = await settleWithin(
|
||||
send('Runtime.evaluate', {
|
||||
expression: `[${PAINTED_EXPRESSION}, performance.timeOrigin]`,
|
||||
@@ -35,7 +39,7 @@ async function unpaintedDocument(send: GuestCdpSender): Promise<number | null> {
|
||||
*/
|
||||
export async function waitForGuestFirstPaint(
|
||||
guest: WebContents,
|
||||
send: GuestCdpSender,
|
||||
send: GuestSessionCdpSender,
|
||||
holdPaint: CapturePaintHold
|
||||
): Promise<void> {
|
||||
if (!isEmbeddedGuest(guest)) {
|
||||
|
||||
@@ -21,15 +21,13 @@ import {
|
||||
|
||||
// Main-session CDP keys follow window focus; guest widget events protect the user's input (#20595).
|
||||
|
||||
export type GuestCdpSender = GuestSessionCdpSender
|
||||
|
||||
// Offscreen and headless pages lack a host frame tree, so CDP already targets them.
|
||||
export function isEmbeddedGuest(webContents: WebContents): boolean {
|
||||
return webContents.getType() === 'webview'
|
||||
}
|
||||
|
||||
// Wait for widget input handling before callers read its effects, matching CDP behavior.
|
||||
async function waitForPageToHandleInput(send: GuestCdpSender): Promise<void> {
|
||||
async function waitForPageToHandleInput(send: GuestSessionCdpSender): Promise<void> {
|
||||
await settleWithin(
|
||||
send('Runtime.evaluate', {
|
||||
// MessageChannel avoids hidden-page timer throttling.
|
||||
@@ -73,7 +71,7 @@ const NO_FOCUS_GUARD: AgentInputFocusGuard = async () => () => {}
|
||||
// Restore user focus after CDP fallback; emulation keeps the page from seeing blur.
|
||||
async function focusGuestForCdpInput(
|
||||
webContents: WebContents,
|
||||
send: GuestCdpSender,
|
||||
send: GuestSessionCdpSender,
|
||||
guardFocus: AgentInputFocusGuard
|
||||
): Promise<() => void> {
|
||||
await enablePageFocusEmulation(send)
|
||||
@@ -85,7 +83,7 @@ async function focusGuestForCdpInput(
|
||||
// Cross-site frame sessions route CDP input without borrowing user focus.
|
||||
async function sendToFrameSession(
|
||||
webContents: WebContents,
|
||||
send: GuestCdpSender,
|
||||
send: GuestSessionCdpSender,
|
||||
sessionId: string,
|
||||
method: string,
|
||||
params: Record<string, unknown>
|
||||
@@ -99,7 +97,7 @@ async function sendToFrameSession(
|
||||
export async function dispatchPageKeyEvent(
|
||||
webContents: WebContents,
|
||||
params: Record<string, unknown>,
|
||||
send: GuestCdpSender,
|
||||
send: GuestSessionCdpSender,
|
||||
guardFocus: AgentInputFocusGuard = NO_FOCUS_GUARD
|
||||
): Promise<unknown> {
|
||||
return await dispatchPageKeyEvents(webContents, [params], send, guardFocus)
|
||||
@@ -112,7 +110,7 @@ const isTabDown = (params: Record<string, unknown>): boolean =>
|
||||
export async function dispatchPageKeyEvents(
|
||||
webContents: WebContents,
|
||||
events: readonly Record<string, unknown>[],
|
||||
send: GuestCdpSender,
|
||||
send: GuestSessionCdpSender,
|
||||
guardFocus: AgentInputFocusGuard = NO_FOCUS_GUARD
|
||||
): Promise<unknown> {
|
||||
let result: unknown = {}
|
||||
@@ -211,7 +209,7 @@ export async function releaseHeldPageInput(
|
||||
release: HeldInputRelease,
|
||||
guardFocus: AgentInputFocusGuard
|
||||
): Promise<unknown> {
|
||||
const send: GuestCdpSender = (method, params, sessionId) =>
|
||||
const send: GuestSessionCdpSender = (method, params, sessionId) =>
|
||||
sendGuestCdpCommand(webContents, method, params, sessionId)
|
||||
// The command's debugger lease may already have detached.
|
||||
const lease = acquireElectronDebugger(webContents)
|
||||
@@ -245,7 +243,7 @@ export type TextInsertionRoute = {
|
||||
export async function routePageTextInsertion(
|
||||
webContents: WebContents,
|
||||
params: Record<string, unknown>,
|
||||
send: GuestCdpSender,
|
||||
send: GuestSessionCdpSender,
|
||||
guardFocus: AgentInputFocusGuard = NO_FOCUS_GUARD
|
||||
): Promise<TextInsertionRoute> {
|
||||
const sendText = (insertParams: Record<string, unknown>): Promise<unknown> =>
|
||||
|
||||
@@ -15,12 +15,10 @@ import type { CookieClearIdentity } from './storage/cookie-store-contracts'
|
||||
import { isNonTransplantableCookieDomain } from './policy/cookie-import-exclusions'
|
||||
import { normalizeCookieDomain } from './policy/cookie-domain'
|
||||
|
||||
export type BrowserPartitionCookieCopyCounts = WslMoveBrowserCookieCopyCounts
|
||||
|
||||
export type BrowserPartitionCookieCopyPlan = {
|
||||
writes: CookieClearIdentity[]
|
||||
/** Skip and reject counts; the copy adds the write results. */
|
||||
counts: BrowserPartitionCookieCopyCounts
|
||||
counts: WslMoveBrowserCookieCopyCounts
|
||||
}
|
||||
|
||||
/** Pure: what to write from `source` into a jar that already holds `destination`. */
|
||||
@@ -76,7 +74,7 @@ export function planBrowserPartitionCookieCopy(
|
||||
export async function copyBrowserPartitionCookies(
|
||||
sourcePartition: string,
|
||||
destinationPartition: string
|
||||
): Promise<BrowserPartitionCookieCopyCounts> {
|
||||
): Promise<WslMoveBrowserCookieCopyCounts> {
|
||||
if (sourcePartition === destinationPartition) {
|
||||
throw new Error('browser_partition_cookie_copy_same_partition')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user