[BUG (or needs better documentation?)] `KEEP_ALIVE` + `PREBOOT_CHROME` doesn't store disk cache
See original GitHub issueFirst, thanks for the amazing project!!!
Context:
- Playwright Version: 1.24.1
- Operating System: Linux
- Python version: 3.8
- Browser: Chromium
- Extra: [any specific details about your environment]
Code Snippet
# docker run --rm -e "PREBOOT_CHROME=true" -e "KEEP_ALIVE=true" -e "DEFAULT_USER_DATA_DIR=/tmp/my-profile" -p 3000:3000 --name browserless browserless/chrome
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
for browser_type in [p.chromium]:
browser = browser_type.connect_over_cdp('ws://127.0.0.1:3000')
page = browser.new_page()
page.goto('https://theguardian.co.uk/')
browser.close()
Then after, disk cache files are non-present
$ docker exec -it browserless bash
blessuser@fff77fd5abb9:/usr/src/app$ find /tmp/my-profile/ -type f|grep -i cache
/tmp/my-profile/Default/Code Cache/wasm/index
/tmp/my-profile/Default/Code Cache/wasm/index-dir/the-real-index
/tmp/my-profile/Default/Code Cache/js/index
/tmp/my-profile/Default/Code Cache/js/index-dir/the-real-index
/tmp/my-profile/Default/GPUCache/data_1
/tmp/my-profile/Default/GPUCache/data_3
/tmp/my-profile/Default/GPUCache/data_2
/tmp/my-profile/Default/GPUCache/index
/tmp/my-profile/Default/GPUCache/data_0
Describe the bug
https://docs.browserless.io/docs/docker.html#keeping-chrome-alive
When using KEEP_ALIVE Chrome will retain information about prior-sessions such as cookies and login contexts. You’ll also need to replace browser.close() with browser.disconnect() in your puppeteer code.
Looks like there is no browser.disconnect()
in playwright-python, so two questions I guess are
- Is
browser.disconnect()
something that can be added in the future? Should this issue be converted to [feature]? - Is my assumption that
.disconnect()
will preserve disk cache data correct?
What I’m really trying to solve
Trying to find a way to make disk cache re-usable between browser contexts of the same connection URL that uses the same --user-data-dir
ws://127.0.0.1:3000?stealth=1&--disable-web-security=true&--user-data-dir=/tmp/test-user-1
(essentially, not having a reusable disk cache is starting to cost $ in BW 😦, I’ve tried solutions like grafting on requests_cache
https://gist.github.com/dgtlmoon/6f306e321200af521f82843bd4bc9901, but that leads to other issues )
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:12 (5 by maintainers)
Closing as per above which should work, if not, please re-file!
@mxschmitt sorry low on time, but I will revisit this soon, thanks for your help as always!