mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-08-10 07:20:39 -04:00
read/write chromium local state
This commit is contained in:
parent
efa214964e
commit
84753c87af
1 changed files with 20 additions and 1 deletions
|
@ -138,7 +138,6 @@ class Browser:
|
||||||
self.chrome_port = self._find_available_port()
|
self.chrome_port = self._find_available_port()
|
||||||
self._work_dir = tempfile.TemporaryDirectory()
|
self._work_dir = tempfile.TemporaryDirectory()
|
||||||
data_dir = os.path.join(self._work_dir.name, "chrome-user-data")
|
data_dir = os.path.join(self._work_dir.name, "chrome-user-data")
|
||||||
flags_location = os.path.join(data_dir, "Local State")
|
|
||||||
if cookie_db is not None:
|
if cookie_db is not None:
|
||||||
cookie_dir = os.path.join(data_dir, "Default")
|
cookie_dir = os.path.join(data_dir, "Default")
|
||||||
cookie_location = os.path.join(cookie_dir, "Cookies")
|
cookie_location = os.path.join(cookie_dir, "Cookies")
|
||||||
|
@ -154,6 +153,15 @@ class Browser:
|
||||||
"exception writing cookie file at %s",
|
"exception writing cookie file at %s",
|
||||||
cookie_location, exc_info=True)
|
cookie_location, exc_info=True)
|
||||||
|
|
||||||
|
flags_location = os.path.join(data_dir, "Local State")
|
||||||
|
try:
|
||||||
|
with open(flags_location, 'w+') as f:
|
||||||
|
json.dump(make_local_state, f)
|
||||||
|
except OSError:
|
||||||
|
self.logger.error(
|
||||||
|
"exception writing local state file at %s",
|
||||||
|
flags_location, exc_info=True)
|
||||||
|
|
||||||
self._chrome_instance = Chrome(
|
self._chrome_instance = Chrome(
|
||||||
port=self.chrome_port, executable=self.chrome_exe,
|
port=self.chrome_port, executable=self.chrome_exe,
|
||||||
user_home_dir=self._work_dir.name,
|
user_home_dir=self._work_dir.name,
|
||||||
|
@ -205,6 +213,17 @@ class Browser:
|
||||||
cookie_location, exc_info=True)
|
cookie_location, exc_info=True)
|
||||||
return cookie_db
|
return cookie_db
|
||||||
|
|
||||||
|
def make_chromium_local_state(self):
|
||||||
|
local_state_location = '/tmp/chromium/Local State'
|
||||||
|
with open(local_state_location) as j:
|
||||||
|
local_state = json.load(j)
|
||||||
|
if 'enabled_labs_experiments' in local_state['browser']:
|
||||||
|
if 'enable-brotli@2' not in local_state['browser']['enabled_labs_experiments']:
|
||||||
|
local_state['browser']['enabled_labs_experiments'].append('enable-brotli@2')
|
||||||
|
else:
|
||||||
|
local_state['browser']['enabled_labs_experiments'] = ['enable-brotli@2']
|
||||||
|
return local_state
|
||||||
|
|
||||||
def _find_available_port(self):
|
def _find_available_port(self):
|
||||||
port_available = False
|
port_available = False
|
||||||
port = self.chrome_port
|
port = self.chrome_port
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue