microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.42k stars 3.63k forks source link

firefox.launchPersistentContext fails with Timeout 30000ms exceeded when data directory already exists #12632

Closed kayleewright-bluescape closed 2 years ago

kayleewright-bluescape commented 2 years ago

Playwright versions tested: 1.19.2, 1.18 OS: MacOS 11.6 Browser affected: firefox

Can reproduce this even while working in the node interpreter as well as a simple JS script. Note that I have also tested this on my windows 10 machine and it works fine there. Chromium on mac also works fine.

//delete data dir before starting
const firefox = require('playwright').firefox
firefox.launchPersistentContext(`./playwrightData`, { headless: false }).then(browser => {browser.close()})

The second time you launch the persistent context you will get a 30000ms timeout error. The browser does appear to be launched and fully working though.

Here are the protocol logs:

> firefox.launchPersistentContext(`./playwrightData`, { headless: false }).then(browser => {browser.close()})
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 1770,
  [Symbol(trigger_async_id_symbol)]: 1767,
  [Symbol(destroyed)]: { destroyed: false }
}
>   pw:protocol SEND ► {"id":1,"method":"Browser.enable","params":{"attachToDefaultContext":true}} +2m
  pw:protocol SEND ► {"id":2,"method":"Browser.getInfo"} +0ms
  pw:protocol SEND ► {"id":3,"method":"Browser.setDownloadOptions","params":{"downloadOptions":{"behavior":"saveToDisk","downloadsDir":"/var/folders/33/bm21c4px5n7dqdhvhzx9fb3m0000gp/T/playwright-artifacts-333pvq"}}} +1ms
  pw:protocol SEND ► {"id":4,"method":"Browser.setDefaultViewport","params":{"viewport":{"viewportSize":{"width":1280,"height":720},"deviceScaleFactor":1}}} +0ms
  pw:protocol SEND ► {"id":5,"method":"Browser.setColorScheme","params":{"colorScheme":"light"}} +0ms
  pw:protocol SEND ► {"id":6,"method":"Browser.setReducedMotion","params":{"reducedMotion":"no-preference"}} +0ms
  pw:protocol SEND ► {"id":7,"method":"Browser.setForcedColors","params":{"forcedColors":"none"}} +0ms
  pw:protocol ◀ RECV {"id":2,"result":{"version":"Firefox/96.0.1","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:96.0) Gecko/20100101 Firefox/96.0"}} +552ms
  pw:protocol ◀ RECV {"id":3} +1ms
  pw:protocol ◀ RECV {"id":4} +0ms
  pw:protocol ◀ RECV {"id":5} +0ms
  pw:protocol ◀ RECV {"id":6} +0ms
  pw:protocol ◀ RECV {"id":7} +0ms
  pw:protocol ◀ RECV {"method":"Browser.attachedToTarget","params":{"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9","targetInfo":{"targetId":"adb1cea4-0e17-4e4b-a760-ffa8efb1989b","type":"page"}}} +423ms
  pw:protocol SEND ► {"method":"Page.addScriptToEvaluateOnNewDocument","params":{"script":"","worldName":"__playwright_utility_world__"},"id":8,"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +0ms
  pw:protocol ◀ RECV {"method":"Page.frameAttached","params":{"frameId":"frame-22"},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +78ms
  pw:protocol ◀ RECV {"method":"Page.navigationCommitted","params":{"frameId":"frame-22","url":"about:blank","name":""},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +1ms
  pw:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"executionContextId":"id-1","auxData":{"frameId":"frame-22","name":""}},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +0ms
  pw:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"executionContextId":"id-2","auxData":{"frameId":"frame-22","name":"__playwright_utility_world__"}},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +0ms
  pw:protocol ◀ RECV {"id":8,"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +1ms
  pw:protocol ◀ RECV {"method":"Page.navigationStarted","params":{"frameId":"frame-22","navigationId":"18206366367745","url":"about:blank"},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +432ms
  pw:protocol ◀ RECV {"method":"Runtime.executionContextDestroyed","params":{"executionContextId":"id-1"},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +29ms
  pw:protocol ◀ RECV {"method":"Runtime.executionContextDestroyed","params":{"executionContextId":"id-2"},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +0ms
  pw:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"executionContextId":"id-3","auxData":{"frameId":"frame-22","name":""}},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +0ms
  pw:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"executionContextId":"id-4","auxData":{"frameId":"frame-22","name":"__playwright_utility_world__"}},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +3ms
  pw:protocol ◀ RECV {"method":"Page.navigationCommitted","params":{"frameId":"frame-22","navigationId":"18206366367745","url":"about:blank","name":""},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +6ms
  pw:protocol ◀ RECV {"method":"Page.ready","sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +6ms
  pw:protocol ◀ RECV {"method":"Page.eventFired","params":{"frameId":"frame-22","name":"DOMContentLoaded"},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +99ms
  pw:protocol ◀ RECV {"method":"Page.eventFired","params":{"frameId":"frame-22","name":"load"},"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +7ms
  pw:protocol ◀ RECV {"id":1} +146ms
  pw:protocol SEND ► {"method":"Page.close","params":{"runBeforeUnload":false},"id":9,"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +2ms
  pw:protocol ◀ RECV {"id":9,"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9"} +52ms
  pw:protocol ◀ RECV {"method":"Browser.detachedFromTarget","params":{"sessionId":"b47946e4-be7a-4550-983c-1fdb377343f9","targetId":"adb1cea4-0e17-4e4b-a760-ffa8efb1989b"}} +29ms

> firefox.launchPersistentContext(`./playwrightData`, { headless: false }).then(browser => {browser.close()})
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 2366,
  [Symbol(trigger_async_id_symbol)]: 2363,
  [Symbol(destroyed)]: { destroyed: false }
}
>   pw:protocol SEND ► {"id":1,"method":"Browser.enable","params":{"attachToDefaultContext":true}} +9s
  pw:protocol SEND ► {"id":2,"method":"Browser.getInfo"} +0ms
  pw:protocol SEND ► {"id":3,"method":"Browser.setDownloadOptions","params":{"downloadOptions":{"behavior":"saveToDisk","downloadsDir":"/var/folders/33/bm21c4px5n7dqdhvhzx9fb3m0000gp/T/playwright-artifacts-O526TX"}}} +0ms
  pw:protocol SEND ► {"id":4,"method":"Browser.setDefaultViewport","params":{"viewport":{"viewportSize":{"width":1280,"height":720},"deviceScaleFactor":1}}} +0ms
  pw:protocol SEND ► {"id":5,"method":"Browser.setColorScheme","params":{"colorScheme":"light"}} +0ms
  pw:protocol SEND ► {"id":6,"method":"Browser.setReducedMotion","params":{"reducedMotion":"no-preference"}} +0ms
  pw:protocol SEND ► {"id":7,"method":"Browser.setForcedColors","params":{"forcedColors":"none"}} +0ms
  pw:protocol ◀ RECV {"id":2,"result":{"version":"Firefox/96.0.1","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:96.0) Gecko/20100101 Firefox/96.0"}} +372ms
  pw:protocol ◀ RECV {"id":3} +0ms
  pw:protocol ◀ RECV {"id":4} +0ms
  pw:protocol ◀ RECV {"id":5} +0ms
  pw:protocol ◀ RECV {"id":6} +1ms
  pw:protocol ◀ RECV {"id":7} +0ms
  pw:protocol ◀ RECV {"method":"Browser.attachedToTarget","params":{"sessionId":"9e608503-774a-48f1-b418-f610d4279af1","targetInfo":{"targetId":"679a30f3-7080-486f-a517-cb80a32cf681","type":"page"}}} +417ms
  pw:protocol SEND ► {"method":"Page.addScriptToEvaluateOnNewDocument","params":{"script":"","worldName":"__playwright_utility_world__"},"id":8,"sessionId":"9e608503-774a-48f1-b418-f610d4279af1"} +1ms
  pw:protocol ◀ RECV {"method":"Page.frameAttached","params":{"frameId":"frame-31"},"sessionId":"9e608503-774a-48f1-b418-f610d4279af1"} +395ms
  pw:protocol ◀ RECV {"method":"Page.navigationCommitted","params":{"frameId":"frame-31","url":"about:blank","name":""},"sessionId":"9e608503-774a-48f1-b418-f610d4279af1"} +1ms
  pw:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"executionContextId":"id-1","auxData":{"frameId":"frame-31","name":""}},"sessionId":"9e608503-774a-48f1-b418-f610d4279af1"} +0ms
  pw:protocol ◀ RECV {"method":"Page.navigationStarted","params":{"frameId":"frame-31","navigationId":"18270790877185","url":"about:blank"},"sessionId":"9e608503-774a-48f1-b418-f610d4279af1"} +0ms
  pw:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"executionContextId":"id-2","auxData":{"frameId":"frame-31","name":"__playwright_utility_world__"}},"sessionId":"9e608503-774a-48f1-b418-f610d4279af1"} +1ms
  pw:protocol ◀ RECV {"id":8,"sessionId":"9e608503-774a-48f1-b418-f610d4279af1"} +0ms
  pw:protocol ◀ RECV {"id":1} +570ms
Uncaught:
: Timeout 30000ms exceeded.
=========================== logs ===========================
<launching> /Users/kayleewright/Library/Caches/ms-playwright/firefox-1316/firefox/Nightly.app/Contents/MacOS/firefox -no-remote -wait-for-browser -foreground -profile ./playwrightData -juggler-pipe about:blank
<launched> pid=8507
[pid=8507][out] 
[pid=8507][out] Juggler listening to the pipe
============================================================
    at captureRawStack (/Users/kayleewright/project/.yarn/unplugged/playwright-core-npm-1.19.2-aa48cb477e/node_modules/playwright-core/lib/utils/stackTrace.js:64:17) {
  name: 'TimeoutError'
}
yury-s commented 2 years ago

I can reproduce it locally on macOS 12.2.1

mxschmitt commented 2 years ago
const playwright = require('playwright');

(async () => {
  for(let i = 0; i < 2; i++) {
    const context = await playwright.firefox.launchPersistentContext('./foo', {
      headless: false,
    });
    await context.close();
  }
})();

I can repro.

scarbon commented 2 years ago

I get the same timeout issue (I can reproduce it). I also notice that the if I open a new Tab on the browser window that get lunch it then works. So it's seems that its stuck in something. The issue seems to happen only in Headless = False.

kururua commented 2 years ago

I deleted the session files and it worked.

const playwright = require('playwright');
const fs = require('fs').promises;

(async () => {
  for(let i = 0; i < 2; i++) {
    const context = await playwright.firefox.launchPersistentContext('./foo', {
      headless: false,
    });
    await context.close();
    await Promise.all([
      fs.rm('./foo/sessionstore-backups', { recursive: true, force: true }),
      fs.rm('./foo/sessionCheckpoints.json', { recursive: true, force: true }),
      fs.rm('./foo/sessionstore.jsonlz4', { recursive: true, force: true }),
    ]);
  }
})();
andrewdbond commented 2 years ago

The issue's title should likely be changed at least to no longer say it's "on Mac" as the issue seems cross-platform; a committer to this repo/a member of Microsoft closed and folded the similar Windows issue https://github.com/microsoft/playwright-dotnet/issues/2070 into this one. Thanks.

aslushnikov commented 2 years ago

For the record:

This should be fixed with fission refactoring.

shirshak55 commented 2 years ago

I still see this error on windows

ERR browserType.launchPersistentContext: Timeout 30000ms exceeded.
=========================== logs ===========================
<launching> C:\Users\user\AppData\Local\ms-playwright\firefox-1323\firefox\firefox.exe -no-remote -wait-for-browser -foreground -profile ./chrome_cache -juggler-pipe about:blank
<launched> pid=13340
[pid=13340][out]
[pid=13340][out] Juggler listening to the pipe
dgozman commented 2 years ago

This is fixed for the 1.24 release.