Add String.replaceAll polyfill

See #6047
This commit is contained in:
Florian Bruhin 2021-01-22 10:50:36 +01:00
parent 222f1f19a1
commit 28a694e17c
3 changed files with 34 additions and 0 deletions

View File

@ -230,6 +230,10 @@ Fixed
- A bug in QtWebEngine 5.15.2 causes "renderer process killed" errors on
websites like LinkedIn and TradingView. There is now a workaround in qutebrowser
to prevent this from happening.
- Nextcloud Calendars started using `String.replaceAll` which was only added to
Chromium recently (Chrome 85), so won't work with current QtWebEngine
versions. This release includes a workaround (a polyfill as a
site-specific-quirk).
v1.14.1 (2020-12-04)
--------------------

View File

@ -1144,6 +1144,13 @@ class _WebEngineScripts(QObject):
QWebEngineScript.DocumentReady,
QWebEngineScript.ApplicationWorld,
),
# FIXME not needed with 5.15.3 most likely, but how do we check for
# that?
(
'string_replaceall',
QWebEngineScript.DocumentCreation,
QWebEngineScript.MainWorld,
),
]
if not qtutils.version_check('5.13'):
quirks.append(('globalthis',

View File

@ -0,0 +1,23 @@
// Based on: https://vanillajstoolkit.com/polyfills/stringreplaceall/
/* eslint-disable no-extend-native */
/**
* String.prototype.replaceAll() polyfill
* https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/
* @author Chris Ferdinandi
* @license MIT
*/
"use strict";
if (!String.prototype.replaceAll) {
String.prototype.replaceAll = function(str, newStr) {
// If a regex pattern
if (Object.prototype.toString.call(str).toLowerCase() === "[object regexp]") {
return this.replace(str, newStr);
}
// If a string
return this.replace(new RegExp(str, "g"), newStr);
};
}