Skip to content

Commit ce17024

Browse files
Add basic canvas experiment ability (#1703)
* Add basic canvas experiment ability * Add enabled canvas args in test
1 parent 36123aa commit ce17024

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

injected/integration-test/fingerprint.spec.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Tests for fingerprint defenses. Ensure that fingerprinting is actually being blocked.
33
*/
44
import { test as base, expect } from '@playwright/test';
5-
import { testContextForExtension } from './helpers/harness.js';
5+
import { testContextForExtension, gotoAndWait } from './helpers/harness.js';
66
import { createRequire } from 'node:module';
77

88
// eslint-disable-next-line no-redeclare
@@ -23,13 +23,23 @@ const expectedFingerprintValues = {
2323

2424
const pagePath = '/index.html';
2525
const tests = [{ url: `http://localhost:3220${pagePath}` }, { url: `http://127.0.0.1:8383${pagePath}` }];
26+
const enabledCanvasArgs = {
27+
site: {
28+
enabledFeatures: ['fingerprintingCanvas'],
29+
},
30+
featureSettings: {
31+
fingerprintingCanvas: {
32+
additionalEnabledCheck: 'enabled',
33+
},
34+
},
35+
};
2636

2737
test.describe.serial('All Fingerprint Defense Tests (must run in serial)', () => {
2838
test.describe.serial('Fingerprint Defense Tests', () => {
2939
for (const _test of tests) {
3040
test(`${_test.url} should include anti-fingerprinting code`, async ({ page, altServerPort }) => {
3141
console.log('running:', altServerPort);
32-
await page.goto(_test.url);
42+
await gotoAndWait(page, _test.url, enabledCanvasArgs);
3343
const values = await page.evaluate(() => {
3444
return {
3545
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
@@ -64,7 +74,7 @@ test.describe.serial('All Fingerprint Defense Tests (must run in serial)', () =>
6474
* @param {tests[number]} test
6575
*/
6676
async function runTest(page, test) {
67-
await page.goto(test.url);
77+
await gotoAndWait(page, test.url, enabledCanvasArgs);
6878
const lib = require.resolve('@fingerprintjs/fingerprintjs/dist/fp.js');
6979
await page.addScriptTag({ path: lib });
7080

@@ -117,7 +127,7 @@ test.describe.serial('All Fingerprint Defense Tests (must run in serial)', () =>
117127
tests.forEach((testCase) => {
118128
test(`Fingerprints should not match across first parties ${testCase.url}`, async ({ page, altServerPort }) => {
119129
console.log('running:', altServerPort);
120-
await page.goto(testCase.url);
130+
await gotoAndWait(page, testCase.url, enabledCanvasArgs);
121131

122132
// give it another second just to be sure
123133
await page.waitForTimeout(1000);

injected/src/features/fingerprinting-canvas.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export default class FingerprintingCanvas extends ContentFeature {
66
init(args) {
77
const { sessionKey, site } = args;
88
const domainKey = site.domain;
9+
const additionalEnabledCheck = this.getFeatureSettingEnabled('additionalEnabledCheck');
10+
if (!additionalEnabledCheck) {
11+
// If additionalEnabledCheck is not enabled bail out early.
12+
// This is a temporary measure to allow for experiment rollout without feature enabling in C-S-S experiments.
13+
return;
14+
}
915
const supportsWebGl = this.getFeatureSettingEnabled('webGl');
1016

1117
const unsafeCanvases = new WeakSet();
@@ -41,7 +47,7 @@ export default class FingerprintingCanvas extends ContentFeature {
4147
proxy.overload();
4248

4349
// Known data methods
44-
const safeMethods = ['putImageData', 'drawImage'];
50+
const safeMethods = this.getFeatureSetting('safeMethods') ?? ['putImageData', 'drawImage'];
4551
for (const methodName of safeMethods) {
4652
const safeMethodProxy = new DDGProxy(this, CanvasRenderingContext2D.prototype, methodName, {
4753
apply(target, thisArg, args) {
@@ -58,7 +64,7 @@ export default class FingerprintingCanvas extends ContentFeature {
5864
safeMethodProxy.overload();
5965
}
6066

61-
const unsafeMethods = [
67+
const unsafeMethods = this.getFeatureSetting('unsafeMethods') ?? [
6268
'strokeRect',
6369
'bezierCurveTo',
6470
'quadraticCurveTo',
@@ -94,7 +100,7 @@ export default class FingerprintingCanvas extends ContentFeature {
94100
}
95101

96102
if (supportsWebGl) {
97-
const unsafeGlMethods = [
103+
const unsafeGlMethods = this.getFeatureSetting('unsafeGlMethods') ?? [
98104
'commit',
99105
'compileShader',
100106
'shaderSource',
@@ -164,7 +170,7 @@ export default class FingerprintingCanvas extends ContentFeature {
164170
return result;
165171
}
166172

167-
const canvasMethods = ['toDataURL', 'toBlob'];
173+
const canvasMethods = this.getFeatureSetting('canvasMethods') ?? ['toDataURL', 'toBlob'];
168174
for (const methodName of canvasMethods) {
169175
const proxy = new DDGProxy(this, HTMLCanvasElement.prototype, methodName, {
170176
apply(target, thisArg, args) {

0 commit comments

Comments
 (0)