pythonlib: Fix WebGL injection causing crashing 0.4.4-beta

This commit is contained in:
daijro 2024-11-25 00:20:27 -06:00
parent 145b737069
commit cf3f8e6bde
5 changed files with 22 additions and 21 deletions

View file

@ -456,10 +456,6 @@ def launch_options(
# Convert executable path to a Path object
executable_path = Path(abspath(executable_path))
# Block WebGL by default until a fix is avaliable.
if block_webgl is None:
block_webgl = True
# Handle virtual display
if virtual_display:
env['DISPLAY'] = virtual_display
@ -472,6 +468,10 @@ def launch_options(
if os:
check_valid_os(os)
# webgl_config requires OS to be set
elif webgl_config:
raise ValueError('OS must be set when using webgl_config')
# Add the default addons
add_default_addons(addons, exclude_addons)
@ -565,19 +565,15 @@ def launch_options(
firefox_user_prefs['media.peerconnection.enabled'] = False
# Allow allow_webgl parameter for backwards compatibility
if block_webgl and not launch_options.pop('allow_webgl', False):
if block_webgl or launch_options.pop('allow_webgl', True) is False:
firefox_user_prefs['webgl.disabled'] = True
LeakWarning.warn('block_webgl')
else:
# Warn the user about WebGL
if not i_know_what_im_doing:
print(
'NOTICE: WebGL is known to cause crashing or behave unexpectedly.'
'A fix will be avaliable soon.'
)
# If the user has provided a specific WebGL vendor/renderer pair, use it
if webgl_config:
merge_into(config, sample_webgl(target_os, *webgl_config))
else:
merge_into(config, sample_webgl(target_os))
# Use software rendering to be less unique
merge_into(

View file

@ -35,4 +35,7 @@ ff_version: >-
no_region: >-
Because you did not pass in a locale region, Camoufox will generate one for you.
This can cause suspicion if your IP does not match your locale region.
This can cause suspicion if your IP does not match your locale region.
block_webgl: >-
Disabling WebGL is not recommended. Many WAFs will check if WebGL is enabled.

View file

@ -44,21 +44,23 @@ def sample_webgl(
(vendor, renderer),
)
result = cursor.fetchone()
conn.close()
if not result:
raise ValueError(f'No WebGL data found for vendor "{vendor}" and renderer "{renderer}"')
if result[3] <= 0: # Check OS-specific probability
# Get a list of possible (vendor, renderer) pairs for this OS
cursor.execute(
f'SELECT DISTINCT vendor, renderer FROM webgl_fingerprints WHERE {os} > 0'
)
possible_pairs = cursor.fetchall()
raise ValueError(
f'Vendor "{vendor}" and renderer "{renderer}" combination not valid for {os.title()}.'
f'Vendor "{vendor}" and renderer "{renderer}" combination not valid for {os.title()}.\n'
f'Possible pairs: {", ".join(str(pair) for pair in possible_pairs)}'
)
return {
'vendor': result[0],
'renderer': result[1],
**orjson.loads(result[2]),
}
conn.close()
return orjson.loads(result[2])
# Get all vendor/renderer pairs and their probabilities for this OS
cursor.execute(f'SELECT vendor, renderer, data, {os} FROM webgl_fingerprints WHERE {os} > 0')

View file

@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "camoufox"
version = "0.4.3"
version = "0.4.4-beta"
description = "Wrapper around Playwright to help launch Camoufox"
authors = ["daijro <daijro.dev@gmail.com>"]
license = "MIT"