From d5a5ed35b60cc74216c49cc8f58b4f06f0eb24bc Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Tue, 17 Sep 2024 20:05:22 +0900 Subject: [PATCH] fix: fix `trustedHTML` issue - (Maybe) fix #2339, caused by YouTube's A/B testing --- package.json | 1 + pnpm-lock.yaml | 8 ++++++++ src/renderer.ts | 8 ++++++++ src/reset.d.ts | 2 ++ 4 files changed, 19 insertions(+) diff --git a/package.json b/package.json index 66317df9..43fcb8d8 100644 --- a/package.json +++ b/package.json @@ -214,6 +214,7 @@ "@types/howler": "2.2.11", "@types/html-to-text": "9.0.4", "@types/semver": "7.5.8", + "@types/trusted-types": "2.0.7", "@typescript-eslint/eslint-plugin": "8.6.0", "@typescript-eslint/parser": "8.6.0", "bufferutil": "4.0.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39764145..edc5fc40 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -190,6 +190,9 @@ importers: '@types/semver': specifier: 7.5.8 version: 7.5.8 + '@types/trusted-types': + specifier: 2.0.7 + version: 2.0.7 '@typescript-eslint/eslint-plugin': specifier: 8.6.0 version: 8.6.0(@typescript-eslint/parser@8.6.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) @@ -1137,6 +1140,9 @@ packages: '@types/semver@7.5.8': resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} + '@types/trusted-types@2.0.7': + resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==} + '@types/verror@1.10.10': resolution: {integrity: sha512-l4MM0Jppn18hb9xmM6wwD1uTdShpf9Pn80aXTStnK1C94gtPvJcV2FrDmbOQUAQfJ1cKZHktkQUDwEqaAKXMMg==} @@ -4895,6 +4901,8 @@ snapshots: '@types/semver@7.5.8': {} + '@types/trusted-types@2.0.7': {} + '@types/verror@1.10.10': optional: true diff --git a/src/renderer.ts b/src/renderer.ts index fade8147..800d50d0 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -23,6 +23,14 @@ let isPluginLoaded = false; let isApiLoaded = false; let firstDataLoaded = false; +if (window.trustedTypes && window.trustedTypes.createPolicy && !window.trustedTypes.defaultPolicy) { + window.trustedTypes.createPolicy('default', { + createHTML: (input) => input, + createScriptURL: (input) => input, + createScript: (input) => input, + }); +} + async function listenForApiLoad() { if (!isApiLoaded) { api = document.querySelector('#movie_player'); diff --git a/src/reset.d.ts b/src/reset.d.ts index f9d0390b..bc45bec1 100644 --- a/src/reset.d.ts +++ b/src/reset.d.ts @@ -6,6 +6,7 @@ import type is from 'electron-is'; import type config from './config'; import type { VideoDataChanged } from '@/types/video-data-changed'; import type { t } from '@/i18n'; +import type { trustedTypes } from 'trusted-types'; declare global { interface Compressor { @@ -19,6 +20,7 @@ declare global { } interface Window { + trustedTypes?: typeof trustedTypes; ipcRenderer: typeof electronIpcRenderer; mainConfig: typeof config; electronIs: typeof is;