Skip to content

[Bug]: page.url() returns empty for shortcut/PWA pages #38989

@Mr-ziqiang

Description

@Mr-ziqiang

Version

1.58.0

Steps to reproduce

When connecting to Chrome via chromium.connectOverCDP(), pages opened through Chrome shortcuts (possibly PWA or special app pages) exhibit the following behavior:

  • page.url() returns an empty string ""
  • page.title() times out indefinitely
  • However, native CDP commands work perfectly
  1. Open a page via Chrome shortcut (or PWA installation)

    • Example: Right-click Chrome shortcut → Open as specific page
    • Or install PWA from a website
  2. Start Chrome with remote debugging:

    chrome.exe --remote-debugging-port=9222
  3. Connect via Playwright:

    import { chromium } from 'playwright';
    const browser = await chromium.connectOverCDP('http://localhost:9222');
    const context = browser.contexts()[0];
    const pages = context.pages();
    
    for (const page of pages) {
      console.log('URL:', page.url()); // Some pages return ""
      console.log('Title:', await page.title()); // Times out
    }
  4. Observe that shortcut/PWA pages return empty URL and timeout

Expected behavior

Since CDP layer works perfectly:

  • page.url() should return the actual URL
  • page.title() should return the page title
  • Both should work consistently regardless of how the page was opened

Actual behavior

  • page.url() returns ""
  • page.title() times out
  • CDP commands work fine

Additional context

Workaround

async function getURLSafe(page) {
  const url = page.url();
  if (url) return url;

  // Fallback to CDP
  const cdp = await page.context().newCDPSession(page);
  const history = await cdp.send('Page.getNavigationHistory');
  await cdp.detach();
  return history.entries[history.currentIndex]?.url || '';
}

async function getTitleSafe(page) {
  try {
    return await Promise.race([
      page.title(),
      new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 2000))
    ]);
  } catch {
    const cdp = await page.context().newCDPSession(page);
    const history = await cdp.send('Page.getNavigationHistory');
    await cdp.detach();
    return history.entries[history.currentIndex]?.title || '';
  }
}

Environment

**Playwright Version**: 1.58.0 (Latest)
**Node.js Version**: 18+
**OS**: Windows 10/11
**Browser**: Chrome (connected via CDP)
**Mode**: connectOverCDP

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions