Skip to content

Commit 532c132

Browse files
AlexJohnSadowskiAlex SadowskiSurceBeatsAlex Sadowski
authored
fix(utils): deprecated-api-warnings-from-lighthouse-fixed (#697)
* deprecatedWindowMembers-added * add-changeset * fix(sandbox): filter deprecated window properties to prevent Lighthouse penalty Accessing window.SharedStorage and window.AttributionReporting during sandbox initialization triggers Chrome "Deprecated feature used" warnings, which Lighthouse reads and penalizes Best Practices score (~81 instead of 100). Add a maintainable blocklist (DEPRECATED_WINDOW_PROPERTIES) and filter these properties in both isValidMemberName() and readMainInterfaces() to prevent the property access that triggers the warnings. Closes #313 * adjust-constant * prettier --------- Co-authored-by: Alex Sadowski <alex@zephy.com> Co-authored-by: SurceBeats <subcero@gmail.com> Co-authored-by: Alex Sadowski <asado@softserveinc.com>
1 parent bf2a980 commit 532c132

4 files changed

Lines changed: 56 additions & 2 deletions

File tree

.changeset/polite-jobs-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/partytown': patch
3+
---
4+
5+
Fix Lighthouse deprecated API warnings by skipping Chrome Privacy Sandbox properties (SharedStorage, AttributionReporting) during window introspection

src/lib/sandbox/read-main-platform.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
createElementFromConstructor,
3+
DEPRECATED_WINDOW_PROPERTIES,
34
getConstructorName,
45
getNodeName,
56
isValidMemberName,
@@ -83,6 +84,7 @@ export const readMainInterfaces = () => {
8384
// get all HTML*Element constructors on window
8485
// and create each element to get their implementation
8586
const elms = Object.getOwnPropertyNames(mainWindow)
87+
.filter((interfaceName) => !DEPRECATED_WINDOW_PROPERTIES.has(interfaceName))
8688
.map((interfaceName) => createElementFromConstructor(docImpl, interfaceName))
8789
.filter((elm) => {
8890
if (!elm) {

src/lib/utils.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,27 @@ export const getConstructorName = (obj: Object) => {
3737

3838
export const startsWith = (str: string, val: string) => str.startsWith(val);
3939

40+
// Chrome APIs that trigger deprecation warnings when accessed on window.
41+
// Accessing these during platform introspection causes console noise.
42+
// https://github.com/QwikDev/partytown/issues/694
43+
export const DEPRECATED_WINDOW_PROPERTIES = new Set([
44+
'sharedStorage',
45+
'SharedStorage',
46+
'AttributionReporting',
47+
'attributionReporting',
48+
'AttributionReportingRequestOptions',
49+
'attributionSrc',
50+
'setAttributionReporting',
51+
]);
52+
4053
export const isValidMemberName = (memberName: string) =>
4154
!(
4255
startsWith(memberName, 'webkit') ||
4356
startsWith(memberName, 'toJSON') ||
4457
startsWith(memberName, 'constructor') ||
4558
startsWith(memberName, 'toString') ||
46-
startsWith(memberName, '_')
59+
startsWith(memberName, '_') ||
60+
DEPRECATED_WINDOW_PROPERTIES.has(memberName)
4761
);
4862

4963
export const getLastMemberName = (applyPath: ApplyPath, i?: number) => {

tests/unit/utils.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as assert from 'uvu/assert';
2-
import { createElementFromConstructor } from '../../src/lib/utils';
2+
import {
3+
createElementFromConstructor,
4+
DEPRECATED_WINDOW_PROPERTIES,
5+
isValidMemberName,
6+
} from '../../src/lib/utils';
37
import { suite } from './utils';
48

59
const test = suite();
@@ -51,4 +55,33 @@ test('createElementFromConstructor, HTML', ({ doc }) => {
5155
assert.is(createElementFromConstructor(doc, 'IntersectionObserver'), undefined);
5256
});
5357

58+
test('isValidMemberName rejects deprecated window properties', () => {
59+
for (const prop of DEPRECATED_WINDOW_PROPERTIES) {
60+
assert.is(isValidMemberName(prop), false, `${prop} should be rejected`);
61+
}
62+
});
63+
64+
test('isValidMemberName rejects known invalid prefixes', () => {
65+
assert.is(isValidMemberName('webkitSpeechRecognition'), false);
66+
assert.is(isValidMemberName('toJSON'), false);
67+
assert.is(isValidMemberName('constructor'), false);
68+
assert.is(isValidMemberName('toString'), false);
69+
assert.is(isValidMemberName('_private'), false);
70+
});
71+
72+
test('isValidMemberName accepts valid member names', () => {
73+
assert.is(isValidMemberName('document'), true);
74+
assert.is(isValidMemberName('localStorage'), true);
75+
assert.is(isValidMemberName('fetch'), true);
76+
assert.is(isValidMemberName('HTMLDivElement'), true);
77+
assert.is(isValidMemberName('addEventListener'), true);
78+
});
79+
80+
test('DEPRECATED_WINDOW_PROPERTIES contains expected entries', () => {
81+
assert.ok(DEPRECATED_WINDOW_PROPERTIES.has('SharedStorage'));
82+
assert.ok(DEPRECATED_WINDOW_PROPERTIES.has('sharedStorage'));
83+
assert.ok(DEPRECATED_WINDOW_PROPERTIES.has('AttributionReporting'));
84+
assert.ok(DEPRECATED_WINDOW_PROPERTIES.has('attributionReporting'));
85+
});
86+
5487
test.run();

0 commit comments

Comments
 (0)