kiwix / kiwix-js

Fully portable & lightweight ZIM reader in Javascript
https://www.kiwix.org/
GNU General Public License v3.0
299 stars 124 forks source link

Fancy library doesn't work in browsers that do not support replaceAll #1174

Open Jaifroid opened 9 months ago

Jaifroid commented 9 months ago

replaceAll() is used to construct the magnet link, and this throws an error in browser < Chrome/Edge 85 and Firefox 77. To be clear, this error only surfaces when you try to download a file. But as this is the whole point of the library, it really needs to be fixed...

See https://caniuse.com/?search=replaceAll.

We should probably polyfill that anyway, as the polyfill is available in core-js.

Jaifroid commented 9 months ago

Actually, it's not yet in core-js 3. It's scheduled for 4 (a proposal).

We can get a polyfill like this:

npm install --save es6-string.prototype.replaceall

And where needed:

import 'es6-string.prototype.replaceall'; (although we probably need import '../../../node_modules/xxxx/dist/xxxx/xxxx.js';).

This would have to be added to the dependency grid. See https://github.com/kiwix/kiwix-js/blob/main/ADDING_DEPENDENCIES_NODE_MODULES.md for the method to do this.

Jaifroid commented 9 months ago

@Rishabhg71 This is one that could interest you, as it could effectively fix your library feature for a wider range of browsers.

Greeshmanth1909 commented 8 months ago

Will it be possible to "artificially" define a string.prototype.replaceAll method in the global scope of the program as a temporary fix for this issue until the release?

Jaifroid commented 8 months ago

Will it be possible to "artificially" define a string.prototype.replaceAll method in the global scope of the program as a temporary fix for this issue until the release?

@Greeshmanth1909 I'll entertain any appropriate fix! We're probably a couple of weeks away from releasing v4.0, and it would certainly be good to get this fixed before that release. I don't think replaceAll should be too hard to emulate, and a full polyfill may be overkill.

Jaifroid commented 7 months ago

@Greeshmanth1909 has discovered that this cannot be polyfilled in Kiwix JS due to CORS. However, it could be fixed upstream in kiwix-tools.