garrytan/gstack · warning · Error

Usage: browse goto <url>

Error message

Usage: browse goto <url>

What it means

Usage guard at write-commands.ts:147. The goto command requires a URL argument; args[0] is undefined or empty. This is a pure argument-count check before any URL parsing.

Source

Thrown at browse/src/write-commands.ts:147

  ],
};

export async function handleWriteCommand(
  command: string,
  args: string[],
  session: TabSession,
  bm: BrowserManager
): Promise<string> {
  const page = session.getPage();
  // Frame-aware target for locator-based operations (click, fill, etc.)
  const target = session.getActiveFrameOrPage();
  const inFrame = session.getFrame() !== null;

  switch (command) {
    case 'goto': {
      if (inFrame) throw new Error('Cannot use goto inside a frame. Run \'frame main\' first.');
      const url = args[0];
      if (!url) throw new Error('Usage: browse goto <url>');
      // Clear loadedHtml BEFORE navigation — a timeout after the main-frame commit
      // must not leave stale content that could resurrect on a later context recreation.
      session.clearLoadedHtml();
      const normalizedUrl = await validateNavigationUrl(url);
      const response = await page.goto(normalizedUrl, { waitUntil: 'domcontentloaded', timeout: 15000 });
      const status = response?.status() || 'unknown';
      return `Navigated to ${normalizedUrl} (${status})`;
    }

    case 'back': {
      if (inFrame) throw new Error('Cannot use back inside a frame. Run \'frame main\' first.');
      session.clearLoadedHtml();
      await page.goBack({ waitUntil: 'domcontentloaded', timeout: 15000 });
      return `Back → ${page.url()}`;
    }

    case 'forward': {
      if (inFrame) throw new Error('Cannot use forward inside a frame. Run \'frame main\' first.');

View on GitHub (pinned to 94993f7401)

Solutions

  1. Provide the URL as the first argument: goto <url>
  2. In automation, assert the URL is a non-empty string before invoking goto

Example fix

// before
await handleWriteCommand('goto', [], session, bm)
// after
if (!url) throw new Error('url required')
await handleWriteCommand('goto', [url], session, bm)
Defensive patterns

Strategy: validation

Validate before calling

function requireUrl(args: string[]): string {
  const url = args[0]
  if (!url || typeof url !== 'string') throw new Error('url required')
  return url
}

Type guard

function hasUrlArg(args: string[]): args is [string, ...string[]] {
  return typeof args[0] === 'string' && args[0].length > 0
}

Prevention

When it happens

Trigger: Calling 'goto' with no arguments, or with an empty-string argument (browse goto '').

Common situations: Scripted call where the URL variable was undefined/null coerced to empty; a CLI typo dropping the URL token.

Related errors


AI-assisted analysis of garrytan/gstack@94993f7401 (2026-08-12). Data as JSON: /api/errors/7d253a905b44d2f1. Report an issue: GitHub.