Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

883 B
Raw Blame
import type { Page } from '@stablyai/playwright-test'

type ShortcutOptions = {
  shift?: boolean
}

const modifierKeyByPage = new WeakMap<Page, 'Meta' | 'Control'>()

async function getModifierKey(page: Page): Promise<'Meta' | 'Control'> {
  const cached = modifierKeyByPage.get(page)
  if (cached) {
    return cached
  }

  const isMac = await page.evaluate(() => navigator.userAgent.includes('Mac'))
  const modifierKey = isMac ? 'Meta' : 'Control'
  modifierKeyByPage.set(page, modifierKey)
  return modifierKey
}

// Use Cmd on macOS and Ctrl on Linux/Windows, matching runtime shortcuts.
export async function pressShortcut(
  page: Page,
  key: string,
  options: ShortcutOptions = {}
): Promise<void> {
  const parts: string[] = [await getModifierKey(page)]
  if (options.shift) {
    parts.push('Shift')
  }
  parts.push(key)
  await page.keyboard.press(parts.join('+'))
}