[Help]: Polyfill Node util.TextDecoder
in Web Extension
#165
-
I have been struggling (for the past year) with trying to make my extension (https://github.com/Antyos/vscode-openscad) web-compatible.
I am using From my understanding, I need to polyfill
Where I use const htmlDocument = await vscode.workspace.fs
.readFile(
vscode.Uri.joinPath(this._cheatsheetUri, 'cheatsheet.html')
)
.then((uint8array) => {
const fileContent = new TextDecoder().decode(uint8array);
// console.log(fileContent.toString());
return parse(fileContent.toString());
}); Here's my webpack config: {
// ...
resolve: {
...nodeConfig.resolve,
mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules
fallback: {
// eslint-disable-next-line unicorn/prefer-module
util: require.resolve('util'),
},
},
} Permalink to repo at the time having this issue: https://github.com/Antyos/vscode-openscad/tree/852e5dcb81 Can anyone offer guidance to make this work? I don't really understand Webpack all too well, so if there is a better way of doing this, I'm all ears. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
That shouldn't be needed anymore. Modern browsers have I am using this successfully in my web extensions that need it. Do you have any super special encoding requirements apart from the default ones: https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings |
Beta Was this translation helpful? Give feedback.
That shouldn't be needed anymore. Modern browsers have
TextDecoder
(and encoder) builtin as globals: https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder#browser_compatibility.I am using this successfully in my web extensions that need it. Do you have any super special encoding requirements apart from the default ones: https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings