extractus / feed-extractor

Simplest way to read & normalize RSS/ATOM/JSON feed data

Home Page:https://extractor-demos.pages.dev/feed-extractor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Commit causing Buffer error when executing in browser, not Node environment

willjstevens opened this issue · comments

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

Screenshot 2024-05-18 at 3 19 16 PM

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() : ''

@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.