Open willjstevens opened 6 months ago
@willjstevens this library's browser support is quite limited, making it nearly unusable in that environment. Considering this, would it be best to remove browser compatibility from the project's scope for now?
Well, I have been using it in the browser for testing and analysis, in addition to a backend-Node environment. Limiting it to Node only would only inhibit from other use cases; might cause people to go elsewhere. This is also a JavaScript library and theoretically, anything written in JavaScript should function in any JavaScript engine (browser or Node.) Requiring Node, if anything, could be handled by externalizing Node-only components to external module, over marking as Node only. This would give people choice of how to use it.
This library is nice and is useful. I recommend not limiting it. Just try to rewrite the line above. Or ask, 'is that Buffer optimization necessary?' Or how could it be handled differently?, etc. BTW - thanks for your work on this helpful project.
@willjstevens ok, let me see how we should deal with buffer at the client side.
+1, Buffer API isn't available in Cloudflare Workers. So, I can't use the latest version of the package.
+1, Buffer API isn't available in Cloudflare Workers. So, I can't use the latest version of the package.
@melkikh Cloudflare just rolled out a new update to Node runtime compatibility for Workers, and Buffer is now available. See https://blog.cloudflare.com/more-npm-packages-on-cloudflare-workers-combining-polyfills-and-native-code/
I'm using the latest version there, and it works, but you have to update your wrangler.toml
with:
compatibility_flags = ["nodejs_compat"]
compatibility_date = "2024-09-23"
This commit (line 36 in retrieve.js) breaks the extract call is giving the following error when executing in a browser such as Chrome:
Uncaught (in promise) ReferenceError: Buffer is not defined at __WEBPACK_DEFAULT_EXPORT__ (retrieve.js:58:1) at async extract
The reason is that Buffer object is only available in a Node environment, not in a browser library.
You either want to rewrite it to not depend on that Node Buffer class or rewrite the line something like:
const text = (buffer && Buffer) ? Buffer.from(buffer).toString().trim() : ''