apify / browser-pool

A Node.js library to easily manage and rotate a pool of web browsers, using any of the popular browser automation libraries like Puppeteer, Playwright, or SecretAgent.
87 stars 14 forks source link

Generated `userDataDir` are not removed from the disk #32

Closed MSIH closed 2 years ago

MSIH commented 3 years ago

My /tmp folder is filling up with 1000s of chrome browser session data like cookies and local storage.

drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:40 z1EvRqWIbNseXvZo2saou
drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:38 ZboBqMZWbLjneQ8qXc6l_
drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:39 Zg56KutgK36lXDf0Wl1zm
drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:36 zJWoqBFejkCaAjxl0SGq_
drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:48 ZN1ajYldDtyuiFU1xUbp7
drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:36 zqHD899Hx7amfawm5BDRT
drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:44 ZtXhTSjYuv_MCKVkrUGRl
drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:38 zw13NsDoBSZPxRFCvCtfg
drwxrwxr-x   3 msihadmin msihadmin    4096 May  3 07:51 ZZ66wFo-KSHke6jfozQ7Y
msihadmin@msih004:/tmp$ cd zw13NsDoBSZPxRFCvCtfg/
msihadmin@msih004:/tmp/zw13NsDoBSZPxRFCvCtfg$ cd Default/
msihadmin@msih004:/tmp/zw13NsDoBSZPxRFCvCtfg/Default$ ls
 blob_storage  'Code Cache'   Cookies-journal  'Local Storage'
 Cache          Cookies       GPUCache         'Session Storage'
msihadmin@msih004:/tmp/zw13NsDoBSZPxRFCvCtfg/Default$ 
szmarczak commented 3 years ago

This works as expected. userDataDir is meant to reuse an existing profile and will create a new one if it does not exist.

szmarczak commented 2 years ago

Ah, the issue is that it doesn't remove the directories. Reproducible by running the example from readme.

szmarczak commented 2 years ago

This happens on both playwright and puppeteer

szmarczak commented 2 years ago

It's generated here: https://github.com/apify/browser-pool/blob/2f89cb5273f9b8cfd04c25458bc435bbbc7fa67d/src/launch-context.ts#L80 but it doesn't exist so chrome creates it but doesn't clean it up since it was explicitly provided. Definitely an issue in browser-pool.

szmarczak commented 2 years ago

https://github.com/microsoft/playwright/blob/c4eb2d4b1e17a0de1cea7220be45545c7c524614/src/server/browserType.ts#L146-L149 we don't have to provide userDataDir

szmarczak commented 2 years ago

The bug is since https://github.com/apify/browser-pool/commit/f971af904944e4f202f12ee504801e0d1082f3b2

szmarczak commented 2 years ago

https://github.com/microsoft/playwright/pull/9069