Merge pull request #1298 from dealerweb/fix/push-preferences-sandboxed-frame

fix: stop the push preference mirror from throwing in sandboxed plugin frames
This commit is contained in:
Linus Rath
2026-10-20 21:14:58 +02:00
committed by GitHub
2 changed files with 18 additions and 1 deletions
+14
View File
@@ -31,6 +31,20 @@ describe('writePushPreferences', () => {
await expect(writePushPreferences({ sound: true })).resolves.toBeUndefined();
expect(put).not.toHaveBeenCalled();
});
it('does nothing where reading the Cache store throws', async () => {
// A plugin sandbox frame has an opaque origin: reading `caches` there,
// typeof included, throws a SecurityError.
Object.defineProperty(globalThis, 'caches', {
configurable: true,
get() {
throw new DOMException('Cache storage is disabled because the context is sandboxed', 'SecurityError');
},
});
const { writePushPreferences } = await import('../push-preferences');
await expect(writePushPreferences({ sound: true })).resolves.toBeUndefined();
expect(put).not.toHaveBeenCalled();
});
});
describe('settings store push preference mirror', () => {
+4 -1
View File
@@ -21,8 +21,11 @@ export function pushPreferencesKey(origin: string): string {
}
export async function writePushPreferences(prefs: PushPreferences): Promise<void> {
if (typeof window === 'undefined' || typeof caches === 'undefined') return;
if (typeof window === 'undefined') return;
try {
// A frame sandboxed without allow-same-origin (the plugin sandbox loads
// the settings store too) throws on any read of `caches`, typeof included.
if (typeof caches === 'undefined') return;
const cache = await caches.open(PUSH_STATE_CACHE);
await cache.put(
pushPreferencesKey(window.location.origin),