Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions injected/entry-points/android-adsjs-lm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @module Android integration
*/
import { load, init, updateFeatureArgs } from '../src/content-scope-features.js';
import { processConfig, isBeingFramed } from '../src/utils.js';
import { AndroidMessagingConfig, MessagingContext, Messaging } from '@duckduckgo/messaging';

/**
* Send initial ping once per frame to establish communication with the platform.
* This replaces the per-feature ping that was previously sent in AndroidAdsjsMessagingTransport.
* When response is received, updates all loaded feature configurations.
*
* @param {AndroidMessagingConfig} messagingConfig
* @param {object} processedConfig - The base configuration
*/
async function sendInitialPingAndUpdate(messagingConfig, processedConfig) {
// Only send ping in top context, not in frames
if (isBeingFramed()) {
return;
}

try {
// Create messaging context for the initial ping
const messagingContext = new MessagingContext({
context: 'contentScopeScripts',
env: processedConfig.debug ? 'development' : 'production',
featureName: 'messaging',
});

// Create messaging instance - handles all the subscription/error boilerplate
const messaging = new Messaging(messagingContext, messagingConfig);

if (processedConfig.debug) {
console.log('AndroidAdsjs: Sending initial ping...');
}

// Send the ping request
const response = await messaging.request('initialPing', {});

// Update all loaded features with merged configuration
if (response && typeof response === 'object') {
const updatedConfig = { ...processedConfig, ...response };

await updateFeatureArgs(updatedConfig);
}
} catch (error) {
if (processedConfig.debug) {
console.error('AndroidAdsjs: Initial ping failed:', error);
}
}
}

function initCode() {
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const config = $CONTENT_SCOPE$;
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const userUnprotectedDomains = $USER_UNPROTECTED_DOMAINS$;
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
const userPreferences = $USER_PREFERENCES$;

const processedConfig = processConfig(config, userUnprotectedDomains, userPreferences);

const configConstruct = processedConfig;
const messageCallback = configConstruct.messageCallback;
const messageSecret = configConstruct.messageSecret;
const javascriptInterface = configConstruct.javascriptInterface;
processedConfig.messagingConfig = new AndroidMessagingConfig({
messageSecret,
messageCallback,
javascriptInterface,
target: globalThis,
debug: processedConfig.debug,
});

// Send initial ping asynchronously to update feature configurations when response arrives
sendInitialPingAndUpdate(processedConfig.messagingConfig, processedConfig);

load({
platform: processedConfig.platform,
site: processedConfig.site,
bundledConfig: processedConfig.bundledConfig,
messagingConfig: processedConfig.messagingConfig,
messageSecret: processedConfig.messageSecret,
});

init(processedConfig);
}

initCode();
4 changes: 4 additions & 0 deletions injected/scripts/entry-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const builds = {
input: 'entry-points/android-adsjs.js',
output: ['../build/android/adsjsContentScope.js'],
},
'android-adsjs-lm': {
input: 'entry-points/android-adsjs-lm.js',
output: ['../build/android/adsjsContentScopeLM.js'],
},
windows: {
input: 'entry-points/windows.js',
output: ['../build/windows/contentScope.js'],
Expand Down
11 changes: 11 additions & 0 deletions injected/src/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ export const platformSupport = {
'gpc',
'breakageReporting',
],
'android-adsjs-lm': [
'apiManipulation',
'webCompat',
'fingerprintingHardware',
'fingerprintingScreenSize',
'fingerprintingTemporaryStorage',
'fingerprintingAudio',
'fingerprintingBattery',
'gpc',
'breakageReporting',
],
windows: [
'cookie',
...baseFeatures,
Expand Down
3 changes: 2 additions & 1 deletion injected/src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ interface ImportMeta {
| 'chrome-mv3'
| 'android-broker-protection'
| 'android-autofill-import'
| 'android-adsjs';
| 'android-adsjs'
| 'android-adsjs-lm';
trackerLookup?: Record<string, unknown>;
pageName?: string;
}
Expand Down