question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG (or needs better documentation?)] `KEEP_ALIVE` + `PREBOOT_CHROME` doesn't store disk cache

See original GitHub issue

First, 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mxschmittcommented, Sep 15, 2022

Closing as per above which should work, if not, please re-file!

0reactions
dgtlmooncommented, Sep 15, 2022

@mxschmitt sorry low on time, but I will revisit this soon, thanks for your help as always!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG (or needs better documentation ... - GitHub
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....
Read more >
Chrome doesn't cache images/js/css - Stack Overflow
I want browser to load it from cache directly when someone press F5, as my resources are available in disk cache. – Debajit...
Read more >
Clear cache & cookies - Computer - Google Account Help
When you use a browser, like Chrome, it saves some information from websites in its cache and cookies. Clearing them fixes certain problems,...
Read more >
A Web Developer's Guide to Browser Caching - Medium
In this article, we'll explain the how the browser uses its cache to load pages faster, which factors determine cache duration, and how...
Read more >
Very heavy cache-access makes for serious performance ...
Suddenly get an absurd disk trashing, locking up all of Chrome while it ... had some bugs that lead to a "waiting for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found