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.
Chrome - Automatically open devtools on network and perserve log
Asked Answered
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')
© 2022 - 2025 — McMap. All rights reserved.