diff --git a/www/index.html b/www/index.html index a5f069081..bea2523a8 100644 --- a/www/index.html +++ b/www/index.html @@ -176,11 +176,11 @@
- Currently only Mediawiki-based content (for instance Wikipedia and - Wikivoyage ), and StackExchange , have been thoroughly tested. Dynamic content (e.g. PhET) is only supported in ServiceWorker Mode - (see technical explanation below). + Dynamic content (e.g. PhET, or the proprietary User Interface in Gutenberg and TED Talks ZIMs) is supported in ServiceWorker Mode only (the default), + but not in JQuery mode (see technical explanation below). If you cannot run ServiceWorker mode, then you will most likely be limited to + static Mediawiki-based content (for instance Wikipedia + and Wikivoyage ), and + StackExchange .
For a quick test, you can start with the
@@ -299,36 +299,37 @@ Downloading and storing large archives
Depending on your browser or framework, this app may be capable of running in two different modes, which we call - "JQuery Mode" and "ServiceWorker Mode" for short. There is a toggle under Compatibility Settings in Configuration. + "ServiceWorker Mode" and "JQuery Mode" for short. There is a toggle under Compatibility Settings in Configuration. Here is a technical explanation of what these modes do:
https:
, localhost
, or certain browser extensions). While this mode is
+ not natively supported in Mozilla (Firefox) browser extensions, we provide a functional workaround by re-launching
+ the extension as a Progressive Web App (PWA). Note that this mode cannot run with the file:
protocol
+ (but only IE11 and old Edge allow the app to run by launching index.html
from the file system).
https:
, localhost
,
- or certain browser extensions). While this mode is not natively supported in Mozilla (Firefox) browser
- extensions, we provide a functional workaround by re-launching the extension as a Progressive Web App (PWA).
- Note that this mode cannot run with the file:
protocol (but only IE11 and old Edge allow the app to run
- by launching index.html
from the file system).
+ JQuery Mode: This mode is now deprecated (and does not in fact require JQuery). It is retained for
+ compatibility with older browsers or frameworks that cannot run Service Workers. The mode has limitations which
+ mean that only static content can be displayed, such as that found in Wikipedia / WikiMedia archives and (for now)
+ Stackexchange. It is a way of inserting articles extracted from the ZIM into the DOM (browser document) by injecting
+ the content into an iframe or tab. We then use native DOM methods, or sometimes JQuery, to parse the article's HTML
+ and insert required assets (images, stylesheets, event listeners for hyperlinks, etc.). On old devices, DOM traversal
+ can be slow, but it is compensated for because we do not extract or run JavaScript assets (which would be technically
+ extremely complicated). As a result, for WikiMedia archives this mode is usually quite fast. On the downside, ZIMs
+ that have a proprietary dynamic UI (such as Gutenberg or TED talks) are only partially supported in this mode: the UI
+ does not work, but articles can be searched for and loaded from the search bar.
See About (Technical Information) for an explanation of the difference between these modes:
-We have switched you to ServiceWorker mode (this is now the default). ' + + 'It supports more types of ZIM archives and is much more robust.
' + + 'If you experience problems with this mode, you can switch back to the (now deprecated) JQuery mode. ' + + 'In that case, please report the problems you experienced to us (see About section).
', + 'Change of default content injection mode']; + uiUtil.systemAlert(message[0], message[1]).then(function () { + settingsStore.setItem('defaultModeChangeAlertDisplayed', true, Infinity); + }); + } else if (!params.defaultModeChangeAlertDisplayed && params.contentInjectionMode === 'jquery') { + message = ['Unfortunately, your browser does not appear to support ServiceWorker mode, which is now the default for this app.
' + + 'You can continue to use the app in the (now deprecated) JQuery mode, but note that this mode only works well with ' + + 'ZIM archives that have static content, such as Wikipedia / Wikimedia ZIMs or Stackexchange.
' + + 'If you can, we recommend that you update your browser to a version that supports ServiceWorker mode.
', + 'ServiceWorker mode unsupported']; + uiUtil.systemAlert(message[0], message[1], true, 'Cancel', 'Okay').then(function (result) { + if (result) { + // If user selected OK, then do not display again ever + settingsStore.setItem('defaultModeChangeAlertDisplayed', true, Infinity); + } + }); + } + // This prevents the alert being displayed again this session + params.defaultModeChangeAlertDisplayed = true; + } + /** * Displays or refreshes the API status shown to the user */ @@ -625,9 +672,10 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys decompAPIStatusDiv.innerHTML = 'Decompressor API: ' + apiName; // Add a warning colour to the API Status Panel if any of the above tests failed apiStatusPanel.classList.add(apiPanelClass); - // Set visibility of UI elements according to mode document.getElementById('bypassAppCacheDiv').style.display = params.contentInjectionMode === 'serviceworker' ? 'block' : 'none'; + // Check to see whether we need to alert the user that we have switched to ServiceWorker mode by default + if (!params.defaultModeChangeAlertDisplayed) checkAndDisplayInjectionModeChangeAlert(); } /** @@ -782,15 +830,25 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys } else if (value === 'serviceworker') { var protocol = window.location.protocol; // Since Firefox 103, the ServiceWorker API is not available any more in Webextensions. See https://hg.mozilla.org/integration/autoland/rev/3a2907ad88e8 and https://bugzilla.mozilla.org/show_bug.cgi?id=1593931 - // Previously, the API was available, but failed to register (which we could trap a fews lines below). + // Previously, the API was available, but failed to register (which we could trap a few lines below). // So we now need to suggest a switch to the PWA if we are inside a Firefox Extension and the ServiceWorker API is unavailable. // Even if some older firefox versions do not support ServiceWorkers at all (versions 42, 43, 45ESR, 52ESR, 60ESR and 68ESR, based on https://caniuse.com/serviceworkers). In this case, the PWA will not work either. if (protocol === 'moz-extension:' && !isServiceWorkerAvailable()) { launchMozillaExtensionServiceWorker(); } else { if (!isServiceWorkerAvailable()) { - uiUtil.systemAlert('The ServiceWorker API is not available on your device. Falling back to JQuery mode', 'ServiceWorker API not available').then(function () { - setContentInjectionMode('jquery'); + var message = + 'Unfortunately, your browser does not appear to support ServiceWorker mode, which is now the default for this app.
' + + 'You can continue to use the app in the (now deprecated) JQuery mode, but note that this mode only works well with ' + + 'ZIM archives that have static content, such as Wikipedia / Wikimedia ZIMs or Stackexchange.
' + + 'If you can, we recommend that you update your browser to a version that supports ServiceWorker mode.
'; + uiUtil.systemAlert(message, 'ServiceWorker API not available', true, 'Cancel', 'Use JQuery mode').then(function (response) { + if (params.referrerExtensionURL && response) { + var uriParams = '?allowInternetAccess=false&contentInjectionMode=jquery&defaultModeChangeAlertDisplayed=true'; + window.location.href = params.referrerExtensionURL + '/www/index.html' + uriParams; + } else { + setContentInjectionMode('jquery'); + } }); return; } @@ -803,7 +861,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys if (!isServiceWorkerReady()) { $('#serviceWorkerStatus').html("ServiceWorker API available : trying to register it..."); if (navigator.serviceWorker.controller) { - console.log("Active service worker found, no need to register"); + console.log("Active Service Worker found, no need to register"); serviceWorkerRegistration = true; // Remove any jQuery hooks from a previous jQuery session $('#articleContent').contents().remove(); @@ -851,6 +909,12 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys } uiUtil.systemAlert(message, "Failed to register ServiceWorker").then(function () { setContentInjectionMode('jquery'); + // We need to wait for the previous dialogue box to unload fully before attempting to display another + setTimeout(function () { + params.defaultModeChangeAlertDisplayed = false; + settingsStore.removeItem('defaultModeChangeAlertDisplayed'); + checkAndDisplayInjectionModeChangeAlert(); + }, 1200); }); } }); @@ -860,7 +924,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys initOrKeepAliveServiceWorker(); } } - // User has switched to Service Worker mode, so no longer needs the memory cache + // User has switched to ServiceWorker mode, so no longer needs the memory cache // We should empty it to ensure good memory management resetCssCache(); } @@ -913,12 +977,13 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys // DEV: See explanation below for why we access localStorage directly here var PWASuccessfullyLaunched = localStorage.getItem(params.keyPrefix + 'PWA_launch') === 'success'; var allowInternetAccess = settingsStore.getItem('allowInternetAccess') === 'true'; - var message = 'To enable the Service Worker, we need one-time access to our secure server ' + - 'so that the app can re-launch as a Progressive Web App (PWA).To enable the Service Worker, we ' : + ('
We shall attempt to switch you to ServiceWorker mode (this is now the default). ' + + 'It supports more types of ZIM archives and is much more robust.
We '); + message += 'need one-time access to our secure server so that the app can re-launch as a Progressive Web App (PWA). ' + + 'If available, the PWA will work offline, but will auto-update periodically when online as per the ' + + 'Service Worker spec.
You can switch back any time by returning to JQuery mode.
' + + 'WARNING: This will attempt to access the following server:
' + params.PWAServer + '