From 8eed0b9145acab83094ddf0e41bfcd5c88d9f996 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 11 Nov 2021 12:36:06 +0100 Subject: [PATCH] Report "pageInfo" telemetry once, rather than for each rendered page Reporting telemetry, in Firefox, includes using `JSON.stringify` on the data and then sending an event to the `PdfStreamConverter.jsm`-code. In that code the event is handled and `JSON.parse` is used to retrieve the data, and in the "pageInfo"-case we'll then proceed to ignore everything except *the first* such event; see https://searchfox.org/mozilla-central/rev/24fac1ad31fb9c6e9c4c767c6a7ff45d226078f3/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#509-514 All-in-all, sending the "pageInfo" telemetry for each rendered page is thus unnecessary and this patch makes the viewer send it only *once* instead. --- web/app.js | 13 +++++++------ web/base_viewer.js | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/web/app.js b/web/app.js index 28a9d5969..2715fd188 100644 --- a/web/app.js +++ b/web/app.js @@ -1372,7 +1372,12 @@ const PDFViewerApplication = { this._initializeAutoPrint(pdfDocument, openActionPromise); }); - onePageRendered.then(() => { + onePageRendered.then(data => { + this.externalServices.reportTelemetry({ + type: "pageInfo", + timestamp: data.timestamp, + }); + pdfDocument.getOutline().then(outline => { if (pdfDocument !== this.pdfDocument) { return; // The document was closed while the outline resolved. @@ -2315,7 +2320,7 @@ function webViewerResetPermissions() { appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS); } -function webViewerPageRendered({ pageNumber, timestamp, error }) { +function webViewerPageRendered({ pageNumber, error }) { // If the page is still visible when it has finished rendering, // ensure that the page number input loading indicator is hidden. if (pageNumber === PDFViewerApplication.page) { @@ -2341,10 +2346,6 @@ function webViewerPageRendered({ pageNumber, timestamp, error }) { }); } - PDFViewerApplication.externalServices.reportTelemetry({ - type: "pageInfo", - timestamp, - }); // It is a good time to report stream and font types. PDFViewerApplication.pdfDocument.getStats().then(function (stats) { PDFViewerApplication.externalServices.reportTelemetry({ diff --git a/web/base_viewer.js b/web/base_viewer.js index 5f9f67747..9ae9952f8 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -554,7 +554,7 @@ class BaseViewer { if (evt.cssTransform || this._onePageRenderedCapability.settled) { return; } - this._onePageRenderedCapability.resolve(); + this._onePageRenderedCapability.resolve({ timestamp: evt.timestamp }); this.eventBus._off("pagerendered", this._onAfterDraw); this._onAfterDraw = null;