Chrome - Automatically open devtools on network and perserve log
Asked Answered
U

1

6

I am using playwright for test automation. Every test run creates a new instance of chromium. When I pass --auto-open-devtools-for-tabs it opens devtools as expected. But, I need to go one step further and have checkbox Perserve Log enabled. Tests are fast and I need to see requests before redirect.

Umeko answered 27/4, 2021 at 8:16 Comment(0)
M
2

Based on this answer, one trick would be loading the browser with a persistent_context, closing the browser, and then edit the preference file setting the Preserve log value.

user_data_dir = './prefs'
pref_file_path = user_data_dir + '/Default/Preferences'
browser = playwright.chromium.launch_persistent_context(user_data_dir, headless=False, args= ['--auto-open-devtools-for-tabs'])
browser.close()

with open(pref_file_path, 'r') as pref_file:
    data = json.load(pref_file)

data['devtools'] = {
    'preferences': {
        'network_log.preserve-log': '"true"'
    }
}

with open(pref_file_path, 'w') as pref_file:
    json.dump(data, pref_file)

browser = playwright.chromium.launch_persistent_context(user_data_dir, headless=False, args= ['--auto-open-devtools-for-tabs'])
page = browser.new_page()
page.goto('https://mcmap.net/q/1216940/-puppeteer-launch-chromium-with-quot-preserve-log-quot-enabled')
Meridethmeridian answered 27/4, 2021 at 11:16 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.