Skip to content

Commit da201dd

Browse files
committed
For #11838: trigger fallback bar after user clicks in pdf
1 parent 8fc1126 commit da201dd

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

web/app.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ const PDFViewerApplication = {
189189
externalServices: DefaultExternalServices,
190190
_boundEvents: {},
191191
contentDispositionFilename: null,
192+
_hasInteracted: false,
193+
_delayedFallbackFeatureIds: [],
192194

193195
// Called once when the document is loaded.
194196
async initialize(appConfig) {
@@ -867,11 +869,20 @@ const PDFViewerApplication = {
867869
typeof PDFJSDev === "undefined" ||
868870
PDFJSDev.test("MOZCENTRAL || GENERIC")
869871
) {
872+
// For PDFs that contain script and form errors, we should only trigger
873+
// the fallback once the user has interacted with the page.
874+
if (this._delayedFallbackFeatureIds.length === 2 && this._hasInteracted) {
875+
featureId = this._delayedFallbackFeatureIds[0];
876+
// Reset to prevent all click events from showing fallback bar.
877+
this._delayedFallbackFeatureIds = [];
878+
}
879+
870880
// Only trigger the fallback once so we don't spam the user with messages
871881
// for one PDF.
872882
if (this.fellback) {
873883
return;
874884
}
885+
875886
this.fellback = true;
876887
this.externalServices.fallback(
877888
{
@@ -1235,7 +1246,7 @@ const PDFViewerApplication = {
12351246
return false;
12361247
}
12371248
console.warn("Warning: JavaScript is not supported");
1238-
this.fallback(UNSUPPORTED_FEATURES.javaScript);
1249+
this._delayedFallbackFeatureIds.push(UNSUPPORTED_FEATURES.javaScript);
12391250
return true;
12401251
});
12411252

@@ -1317,7 +1328,7 @@ const PDFViewerApplication = {
13171328

13181329
if (info.IsAcroFormPresent) {
13191330
console.warn("Warning: AcroForm/XFA is not supported");
1320-
this.fallback(UNSUPPORTED_FEATURES.forms);
1331+
this._delayedFallbackFeatureIds.push(UNSUPPORTED_FEATURES.forms);
13211332
}
13221333

13231334
if (
@@ -2473,6 +2484,17 @@ function webViewerWheel(evt) {
24732484
}
24742485

24752486
function webViewerClick(evt) {
2487+
PDFViewerApplication._hasInteracted = true;
2488+
2489+
// Avoid triggering the fallback bar when the user clicks on the
2490+
// toolbar or sidebar.
2491+
if (
2492+
PDFViewerApplication._delayedFallbackFeatureIds.length === 2 &&
2493+
PDFViewerApplication.pdfViewer.containsElement(evt.target)
2494+
) {
2495+
PDFViewerApplication.fallback();
2496+
}
2497+
24762498
if (!PDFViewerApplication.secondaryToolbar.isOpen) {
24772499
return;
24782500
}

0 commit comments

Comments
 (0)