Skip to content

Commit b7c3347

Browse files
authored
Merge branch 'main' into dbajpeyi/hack/autofill-bookmark-import
2 parents 9900494 + 5431bb6 commit b7c3347

File tree

6 files changed

+188
-173
lines changed

6 files changed

+188
-173
lines changed

injected/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"seedrandom": "^3.0.5",
3232
"sjcl": "^1.0.8",
3333
"@duckduckgo/privacy-configuration": "github:duckduckgo/privacy-configuration#1752154773643",
34-
"esbuild": "^0.25.9",
34+
"esbuild": "^0.25.10",
3535
"urlpattern-polyfill": "^10.1.0"
3636
},
3737
"devDependencies": {
@@ -43,6 +43,6 @@
4343
"@typescript-eslint/eslint-plugin": "^8.42.0",
4444
"fast-check": "^4.2.0",
4545
"jasmine": "^5.10.0",
46-
"web-ext": "^8.9.0"
46+
"web-ext": "^8.10.0"
4747
}
4848
}

injected/src/features/duck-ai-listener.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ export default class DuckAiListener extends ContentFeature {
9797

9898
async setup() {
9999
this.createButtonUI();
100+
this.setupTelemetry();
100101
await this.setupMessageBridge();
101102
this.setupTextBoxDetection();
102-
this.setupTelemetry();
103103
this.cleanupExistingPrompts();
104104
this.setupPromptCleanupObserver();
105105
}
@@ -834,7 +834,8 @@ export default class DuckAiListener extends ContentFeature {
834834
this.triggerInputEvents();
835835

836836
// Capture prompt text for telemetry before any modifications
837-
if (this.textBox && this.promptTelemetry) {
837+
// Only send telemetry if context hasn't been used yet (first prompt)
838+
if (this.textBox && this.promptTelemetry && !this.hasContextBeenUsed) {
838839
const rawPromptText = this.getRawPromptText();
839840
const totalPromptText = this.textBox.value; // This includes context if enabled
840841
const contextSize = this.pageData?.content?.length || 0;
@@ -1354,10 +1355,13 @@ class DuckAiPromptTelemetry {
13541355
* @param {Object} params - Parameters to send with pixel
13551356
*/
13561357
sendPixel(pixelName, params) {
1357-
if (!globalThis?.DDG?.pixel) {
1358+
if (!globalThis?.DDG?.pixel?.fire) {
1359+
this.log.warn('sendPixel: No pixel object found');
13581360
return;
13591361
}
13601362
globalThis.DDG.pixel.fire(pixelName, params);
1363+
1364+
this.log.info('Pixel sent', { pixelName, params });
13611365
}
13621366

13631367
/**
@@ -1376,6 +1380,7 @@ class DuckAiPromptTelemetry {
13761380
/**
13771381
* Send context pixel info when context is used
13781382
* @param {Object} contextData - Context data object
1383+
* @param {string} pixelName - Name of pixel to fire
13791384
*/
13801385
sendContextPixelInfo(contextData, pixelName) {
13811386
if (!contextData?.content || contextData.content.length === 0) {
@@ -1384,7 +1389,7 @@ class DuckAiPromptTelemetry {
13841389
}
13851390

13861391
this.sendPixel(pixelName, {
1387-
contextLength: contextData.content.length,
1392+
contextLength: contextData.fullContentLength,
13881393
});
13891394
}
13901395

injected/src/features/page-context.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ export default class PageContext extends ContentFeature {
243243
metaDescription: this.getMetaDescription(),
244244
content: mainContent,
245245
truncated,
246+
fullContentLength: this.fullContentLength, // Include full content length before truncation
246247
headings: this.getHeadings(),
247248
links: this.getLinks(),
248249
images: this.getImages(),
@@ -272,7 +273,9 @@ export default class PageContext extends ContentFeature {
272273
}
273274

274275
getMainContent() {
275-
const maxLength = this.getFeatureSetting('maxContentLength') || 950;
276+
const maxLength = this.getFeatureSetting('maxContentLength') || 9500;
277+
// Used to avoid large content serialization
278+
const upperLimit = this.getFeatureSetting('upperLimit') || 500000;
276279
let excludeSelectors = this.getFeatureSetting('excludeSelectors') || ['.ad', '.sidebar', '.footer', '.nav', '.header'];
277280
excludeSelectors = excludeSelectors.concat(['script', 'style', 'link', 'meta', 'noscript', 'svg', 'canvas']);
278281

@@ -296,16 +299,20 @@ export default class PageContext extends ContentFeature {
296299
});
297300

298301
this.log.info('Calling domToMarkdown', clone.innerHTML);
299-
content += domToMarkdown(clone, maxLength);
302+
content += domToMarkdown(clone, upperLimit);
300303
}
304+
content = content.trim();
305+
306+
// Store the full content length before truncation
307+
this.fullContentLength = content.length;
301308

302309
// Limit content length
303310
if (content.length > maxLength) {
304311
this.log.info('Truncating content', content);
305312
content = content.substring(0, maxLength) + '...';
306313
}
307314

308-
return content.trim();
315+
return content;
309316
}
310317

311318
getHeadings() {

0 commit comments

Comments
 (0)