From b2b227e9bf1983b5d54c0009e3992feebfbc8f36 Mon Sep 17 00:00:00 2001 From: Maxim Tsoy Date: Thu, 9 Jan 2025 10:18:27 +0100 Subject: [PATCH] Fix CTL messaging in the MV2 extension (#1378) * Fix CTL messaging in the MV2 extension * Remove CTL from the Android build --- injected/entry-points/chrome.js | 5 +++-- injected/src/features.js | 2 +- injected/src/features/click-to-load.js | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/injected/entry-points/chrome.js b/injected/entry-points/chrome.js index 03a91c63a..ebae03cd2 100644 --- a/injected/entry-points/chrome.js +++ b/injected/entry-points/chrome.js @@ -146,12 +146,13 @@ function init() { return console.warn('no details in sendMessage proxy', event); } - const messageType = event.detail?.messageType; + const eventDetail = JSON.parse(event.detail); + const messageType = eventDetail.messageType; if (!allowedMessages.includes(messageType)) { return console.warn('Ignoring invalid sendMessage messageType', messageType); } - chrome.runtime.sendMessage(event.detail, (response) => { + chrome.runtime.sendMessage(eventDetail, (response) => { const message = { messageType: 'response', responseMessageType: messageType, diff --git a/injected/src/features.js b/injected/src/features.js index 0753c3b1a..895f80b8b 100644 --- a/injected/src/features.js +++ b/injected/src/features.js @@ -33,7 +33,7 @@ const otherFeatures = /** @type {const} */ ([ export const platformSupport = { apple: ['webCompat', ...baseFeatures], 'apple-isolated': ['duckPlayer', 'brokerProtection', 'performanceMetrics', 'clickToLoad', 'messageBridge'], - android: [...baseFeatures, 'webCompat', 'clickToLoad', 'breakageReporting', 'duckPlayer'], + android: [...baseFeatures, 'webCompat', 'breakageReporting', 'duckPlayer'], 'android-autofill-password-import': ['autofillPasswordImport'], windows: ['cookie', ...baseFeatures, 'windowsPermissionUsage', 'duckPlayer', 'brokerProtection', 'breakageReporting'], firefox: ['cookie', ...baseFeatures, 'clickToLoad'], diff --git a/injected/src/features/click-to-load.js b/injected/src/features/click-to-load.js index 7110959a4..5d90430fe 100644 --- a/injected/src/features/click-to-load.js +++ b/injected/src/features/click-to-load.js @@ -1991,7 +1991,7 @@ export default class ClickToLoad extends ContentFeature { get messaging() { if (this._messaging) return this._messaging; - if (this.platform.name === 'android' || this.platform.name === 'extension') { + if (this.platform.name === 'extension') { this._clickToLoadMessagingTransport = new SendMessageMessagingTransport(); const config = new TestTransportConfig(this._clickToLoadMessagingTransport); this._messaging = new Messaging(this.messagingContext, config); @@ -2005,6 +2005,7 @@ export default class ClickToLoad extends ContentFeature { this._messaging = new Messaging(this.messagingContext, config); return this._messaging; } else { + // TODO: Android does support Messaging now, but CTL is not yet integrated there. throw new Error('Messaging not supported yet on platform: ' + this.name); } }