Comments (6)
Yes I get it :/ so I added the proxy CORS thing to avoid these issues.
However I think I will just add a backend endpoint today that handles this. I am just worried the library would have the same errors in the backend as well @jacktuck
from unfurl.
Oh interesting. I get "ReferenceError: Cannot access 'cross_fetch_1' before initialization". I'll see what I can do.
from unfurl.
My workaround (I used this answer here to create a helper app that handles cross origin: https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe):
let raw;
try {
raw = await unfurled(url);
} catch (err) {
/** CORS failed to fetch? retry with cors proxy
* this happens when for example localhost tries to unfurl dev-remote url due to different hosts
* https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe
*/
try {
raw = await unfurled(`${CORS_PROXY_URL}/${url}`);
} catch (err2) {
// handled - proceed and attempt to parse other data - eg: plural
}
// handled - proceed and attempt to parse other data - eg: plural
}
from unfurl.
Refused to set unsafe header "user-agent"
That was a fairly straightforward fix:
911590d#diff-f41e9d04a45c83f3b6f6e630f10117feR42
The reason i was getting
"ReferenceError: Cannot access 'cross_fetch_1' before initialization"
was that I was testing the library directly in codepen with unpkg. I'm guessing you're using a bundler, so you didn't run into this.
But due to the restrictive nature of CORS in the browser, i don't think there is any merit in keeping those fixes around.
Whilst your CORs proxy workaround works, it may not be the right approach. This library is approximately 1MB uncompressed (and 500kb compressed with webpack). So it'd add significant bloat and then when calling unfurl it'll block the event loop.
I recommend changing your CORS proxy service to do the unfurling. There is a great minimalist example here https://github.com/beeman/micro-unfurl
I will make it clearer in the readme that this is a server-side library and not supported for use client-side.
from unfurl.
Do you not get the same CORS error with itaditya/simple-unfurl ?
from unfurl.
You shouldn't have the same issue as you'd have control of the endpoint - meaning you can add CORS response headers - either wildcard or specific to your domain(s).
from unfurl.
Related Issues (20)
- og:image:alt not used HOT 3
- meta theme-color and/or a way to access the scraped HTML? HOT 1
- Installation instructions HOT 2
- Missing types in dist
- Package installation HOT 3
- Favicon HOT 3
- Add semantic releases HOT 3
- Youtube: only favicon gets extracted HOT 2
- Youtube OEmbed not picked up HOT 2
- Incorrect metadata types HOT 2
- Wrong parsing of <title> HOT 6
- Issue scraping Amazon HOT 19
- Add support article type in OGP specification HOT 2
- TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters HOT 4
- Respect robots.txt HOT 1
- [Bug] Incorrect Twitter card result for Gumroad links HOT 3
- Allow passing extra headers to fetch request HOT 2
- Posibility to use axios or enhance the current implementation to work on company proxyfied networks HOT 1
- [Bug]: SoundCloud oEmbed is not returning any html content HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unfurl.