Skip to content

Commit

Permalink
Backwards compatibility with <0.3.0
Browse files Browse the repository at this point in the history
Change ALL webgl keys to webGl. This keeps backwards compatibility with <0.3.0 versions of the Python library.
  • Loading branch information
daijro committed Oct 20, 2024
1 parent 0ff90fc commit 711b5b4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,20 +361,20 @@ Camoufox supports spoofing WebGL parameters, supported extensions, context attri
| Property | Description | Example |
| ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| webgl:renderer | Spoofs the name of the unmasked WebGL renderer. | `"NVIDIA GeForce GTX 980, or similar"` |
| webgl:vendor | Spoofs the name of the unmasked WebGL vendor. | `"NVIDIA Corporation"` |
| webgl:supportedExtensions | An array of supported WebGL extensions ([full list](https://registry.khronos.org/webgl/extensions/)). | `["ANGLE_instanced_arrays", "EXT_color_buffer_float", "EXT_disjoint_timer_query", ...]` |
| webgl2:supportedExtensions | The same as `webgl:supportedExtensions`, but for WebGL2. | `["ANGLE_instanced_arrays", "EXT_color_buffer_float", "EXT_disjoint_timer_query", ...]` |
| webgl:contextAttributes | A dictionary of WebGL context attributes. | `{"alpha": true, "antialias": true, "depth": true, ...}` |
| webgl2:contextAttributes | The same as `webgl:contextAttributes`, but for WebGL2. | `{"alpha": true, "antialias": true, "depth": true, ...}` |
| webgl:parameters | A dictionary of WebGL parameters. Keys must be GL enums, and values are the values to spoof them as. | `{"2849": 1, "2884": false, "2928": [0, 1], ...}` |
| webgl2:parameters | The same as `webgl:parameters`, but for WebGL2. | `{"2849": 1, "2884": false, "2928": [0, 1], ...}` |
| webgl:parameters:blockIfNotDefined | If set to `true`, only the parameters in `webgl:parameters` will be allowed. Can be dangerous if not used correctly. | `true`/`false` |
| webgl2:parameters:blockIfNotDefined | If set to `true`, only the parameters in `webgl2:parameters` will be allowed. Can be dangerous if not used correctly. | `true`/`false` |
| webgl:shaderPrecisionFormats | A dictionary of WebGL shader precision formats. Keys are formatted as `"<shaderType>,<precisionType>"`. | `{"35633,36336": {"rangeMin": 127, "rangeMax": 127, "precision": 23}, ...}` |
| webgl2:shaderPrecisionFormats | The same as `webGL:shaderPrecisionFormats`, but for WebGL2. | `{"35633,36336": {"rangeMin": 127, "rangeMax": 127, "precision": 23}, ...}` |
| webgl:shaderPrecisionFormats:blockIfNotDefined | If set to `true`, only the shader percisions in `webgl:shaderPrecisionFormats` will be allowed. | `true`/`false` |
| webgl2:shaderPrecisionFormats:blockIfNotDefined | If set to `true`, only the shader percisions in `webgl2:shaderPrecisionFormats` will be allowed. | `true`/`false` |
| webGl:renderer | Spoofs the name of the unmasked WebGL renderer. | `"NVIDIA GeForce GTX 980, or similar"` |
| webGl:vendor | Spoofs the name of the unmasked WebGL vendor. | `"NVIDIA Corporation"` |
| webGl:supportedExtensions | An array of supported WebGL extensions ([full list](https://registry.khronos.org/webgl/extensions/)). | `["ANGLE_instanced_arrays", "EXT_color_buffer_float", "EXT_disjoint_timer_query", ...]` |
| webGl2:supportedExtensions | The same as `webGl:supportedExtensions`, but for WebGL2. | `["ANGLE_instanced_arrays", "EXT_color_buffer_float", "EXT_disjoint_timer_query", ...]` |
| webGl:contextAttributes | A dictionary of WebGL context attributes. | `{"alpha": true, "antialias": true, "depth": true, ...}` |
| webGl2:contextAttributes | The same as `webGl:contextAttributes`, but for WebGL2. | `{"alpha": true, "antialias": true, "depth": true, ...}` |
| webGl:parameters | A dictionary of WebGL parameters. Keys must be GL enums, and values are the values to spoof them as. | `{"2849": 1, "2884": false, "2928": [0, 1], ...}` |
| webGl2:parameters | The same as `webGl:parameters`, but for WebGL2. | `{"2849": 1, "2884": false, "2928": [0, 1], ...}` |
| webGl:parameters:blockIfNotDefined | If set to `true`, only the parameters in `webGl:parameters` will be allowed. Can be dangerous if not used correctly. | `true`/`false` |
| webGl2:parameters:blockIfNotDefined | If set to `true`, only the parameters in `webGl2:parameters` will be allowed. Can be dangerous if not used correctly. | `true`/`false` |
| webGl:shaderPrecisionFormats | A dictionary of WebGL shader precision formats. Keys are formatted as `"<shaderType>,<precisionType>"`. | `{"35633,36336": {"rangeMin": 127, "rangeMax": 127, "precision": 23}, ...}` |
| webGl2:shaderPrecisionFormats | The same as `webGL:shaderPrecisionFormats`, but for WebGL2. | `{"35633,36336": {"rangeMin": 127, "rangeMax": 127, "precision": 23}, ...}` |
| webGl:shaderPrecisionFormats:blockIfNotDefined | If set to `true`, only the shader percisions in `webGl:shaderPrecisionFormats` will be allowed. | `true`/`false` |
| webGl2:shaderPrecisionFormats:blockIfNotDefined | If set to `true`, only the shader percisions in `webGl2:shaderPrecisionFormats` will be allowed. | `true`/`false` |
</details>
Expand Down
12 changes: 6 additions & 6 deletions additions/camoucfg/MaskConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ inline std::optional<nlohmann::json> GetNested(const std::string& domain,
template <typename T>
inline std::optional<T> GetAttribute(const std::string attrib, bool isWebGL2) {
auto value = MaskConfig::GetNested(
isWebGL2 ? "webgl2:contextAttributes" : "webgl:contextAttributes",
isWebGL2 ? "webGl2:contextAttributes" : "webGl:contextAttributes",
attrib);
if (!value) return std::nullopt;
return value.value().get<T>();
Expand All @@ -222,7 +222,7 @@ inline std::optional<
std::variant<int64_t, bool, double, std::string, std::nullptr_t>>
GLParam(uint32_t pname, bool isWebGL2) {
auto value =
MaskConfig::GetNested(isWebGL2 ? "webgl2:parameters" : "webgl:parameters",
MaskConfig::GetNested(isWebGL2 ? "webGl2:parameters" : "webGl:parameters",
std::to_string(pname));
if (!value) return std::nullopt;
auto data = value.value();
Expand All @@ -237,7 +237,7 @@ GLParam(uint32_t pname, bool isWebGL2) {
template <typename T>
inline T MParamGL(uint32_t pname, T defaultValue, bool isWebGL2) {
if (auto value = MaskConfig::GetNested(
isWebGL2 ? "webgl2:parameters" : "webgl:parameters",
isWebGL2 ? "webGl2:parameters" : "webGl:parameters",
std::to_string(pname));
value.has_value()) {
return value.value().get<T>();
Expand All @@ -250,7 +250,7 @@ inline std::vector<T> MParamGLVector(uint32_t pname,
std::vector<T> defaultValue,
bool isWebGL2) {
if (auto value = MaskConfig::GetNested(
isWebGL2 ? "webgl2:parameters" : "webgl:parameters",
isWebGL2 ? "webGl2:parameters" : "webGl:parameters",
std::to_string(pname));
value.has_value()) {
if (value.value().is_array()) {
Expand All @@ -266,8 +266,8 @@ inline std::optional<std::array<int32_t, 3UL>> MShaderData(
std::string valueName =
std::to_string(shaderType) + "," + std::to_string(precisionType);
if (auto value =
MaskConfig::GetNested(isWebGL2 ? "webgl2:shaderPrecisionFormats"
: "webgl:shaderPrecisionFormats",
MaskConfig::GetNested(isWebGL2 ? "webGl2:shaderPrecisionFormats"
: "webGl:shaderPrecisionFormats",
valueName)) {
// Convert {rangeMin: int, rangeMax: int, precision: int} to array
auto data = value.value();
Expand Down
22 changes: 11 additions & 11 deletions patches/webgl-spoofing.patch
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ index db60868f65..7361f0fc9c 100644
+ result.mStencil = MBoolVal("stencil", options.stencil);
+ result.mAntialias.Construct(MBoolVal("antialias", options.antialias));
+ result.mPremultipliedAlpha = MBoolVal(
+ "webgl:contextAttributes.premultipliedAlpha", options.premultipliedAlpha);
+ "webGl:contextAttributes.premultipliedAlpha", options.premultipliedAlpha);
+ result.mPreserveDrawingBuffer =
+ MBoolVal("preserveDrawingBuffer", options.preserveDrawingBuffer);
+ result.mFailIfMajorPerformanceCaveat = MBoolVal(
Expand Down Expand Up @@ -161,8 +161,8 @@ index db60868f65..7361f0fc9c 100644
+ case dom::WEBGL_debug_renderer_info_Binding::UNMASKED_VENDOR_WEBGL:
+ break;
+ default:
+ if (MaskConfig::GetBool(mIsWebGL2 ? "webgl2:parameters:blockIfNotDefined"
+ : "webgl:parameters:blockIfNotDefined")) {
+ if (MaskConfig::GetBool(mIsWebGL2 ? "webGl2:parameters:blockIfNotDefined"
+ : "webGl:parameters:blockIfNotDefined")) {
+ retval.set(JS::NullValue());
+ return;
+ }
Expand Down Expand Up @@ -272,7 +272,7 @@ index db60868f65..7361f0fc9c 100644

switch (pname) {
case dom::WEBGL_debug_renderer_info_Binding::UNMASKED_RENDERER_WEBGL:
+ if (auto value = MaskConfig::GetString("webgl:renderer")) {
+ if (auto value = MaskConfig::GetString("webGl:renderer")) {
+ ret = Some(value.value());
+ break;
+ }
Expand All @@ -283,7 +283,7 @@ index db60868f65..7361f0fc9c 100644
break;

case dom::WEBGL_debug_renderer_info_Binding::UNMASKED_VENDOR_WEBGL:
+ if (auto value = MaskConfig::GetString("webgl:vendor")) {
+ if (auto value = MaskConfig::GetString("webGl:vendor")) {
+ ret = Some(value.value());
+ break;
+ }
Expand Down Expand Up @@ -317,8 +317,8 @@ index db60868f65..7361f0fc9c 100644
+ }
+ // Check if block if not defined is on
+ if (MaskConfig::GetBool(
+ mIsWebGL2 ? "webgl2:shaderPrecisionFormats:blockIfNotDefined"
+ : "webgl:shaderPrecisionFormats:blockIfNotDefined")) {
+ mIsWebGL2 ? "webGl2:shaderPrecisionFormats:blockIfNotDefined"
+ : "webGl:shaderPrecisionFormats:blockIfNotDefined")) {
+ Maybe<webgl::ShaderPrecisionFormat> ret;
+ return ret;
+ }
Expand All @@ -331,8 +331,8 @@ index db60868f65..7361f0fc9c 100644
}

+ if (std::vector<std::string> maskValues =
+ MaskConfig::GetStringList(mIsWebGL2 ? "webgl2:supportedExtensions"
+ : "webgl:supportedExtensions");
+ MaskConfig::GetStringList(mIsWebGL2 ? "webGl2:supportedExtensions"
+ : "webGl:supportedExtensions");
+ !maskValues.empty()) {
+ if (std::find(maskValues.begin(), maskValues.end(),
+ GetExtensionName(ext)) != maskValues.end()) {
Expand All @@ -351,8 +351,8 @@ index db60868f65..7361f0fc9c 100644
+
+ // Implement separately to prevent O(n^2) timing
+ if (std::vector<std::string> maskValues =
+ MaskConfig::GetStringList(mIsWebGL2 ? "webgl2:supportedExtensions"
+ : "webgl:supportedExtensions");
+ MaskConfig::GetStringList(mIsWebGL2 ? "webGl2:supportedExtensions"
+ : "webGl:supportedExtensions");
+ !maskValues.empty()) {
+ for (const auto& ext : maskValues) {
+ retarr.AppendElement(NS_ConvertUTF8toUTF16(ext));
Expand Down
28 changes: 14 additions & 14 deletions settings/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@
{ "property": "AudioContext:sampleRate", "type": "uint" },
{ "property": "AudioContext:outputLatency", "type": "double" },
{ "property": "AudioContext:maxChannelCount", "type": "uint" },
{ "property": "webgl:renderer", "type": "str" },
{ "property": "webgl:vendor", "type": "str" },
{ "property": "webgl:supportedExtensions", "type": "array" },
{ "property": "webgl2:supportedExtensions", "type": "array" },
{ "property": "webgl:parameters", "type": "dict" },
{ "property": "webgl:parameters:blockIfNotDefined", "type": "bool" },
{ "property": "webgl2:parameters", "type": "dict" },
{ "property": "webgl2:parameters:blockIfNotDefined", "type": "bool" },
{ "property": "webgl:shaderPrecisionFormats", "type": "dict" },
{ "property": "webgl:shaderPrecisionFormats:blockIfNotDefined", "type": "bool" },
{ "property": "webgl2:shaderPrecisionFormats", "type": "dict" },
{ "property": "webgl2:shaderPrecisionFormats:blockIfNotDefined", "type": "bool" },
{ "property": "webgl:contextAttributes", "type": "dict" },
{ "property": "webgl2:contextAttributes", "type": "dict" },
{ "property": "webGl:renderer", "type": "str" },
{ "property": "webGl:vendor", "type": "str" },
{ "property": "webGl:supportedExtensions", "type": "array" },
{ "property": "webGl2:supportedExtensions", "type": "array" },
{ "property": "webGl:parameters", "type": "dict" },
{ "property": "webGl:parameters:blockIfNotDefined", "type": "bool" },
{ "property": "webGl2:parameters", "type": "dict" },
{ "property": "webGl2:parameters:blockIfNotDefined", "type": "bool" },
{ "property": "webGl:shaderPrecisionFormats", "type": "dict" },
{ "property": "webGl:shaderPrecisionFormats:blockIfNotDefined", "type": "bool" },
{ "property": "webGl2:shaderPrecisionFormats", "type": "dict" },
{ "property": "webGl2:shaderPrecisionFormats:blockIfNotDefined", "type": "bool" },
{ "property": "webGl:contextAttributes", "type": "dict" },
{ "property": "webGl2:contextAttributes", "type": "dict" },
{ "property": "debug", "type": "bool" }
]

0 comments on commit 711b5b4

Please sign in to comment.