Comments (7)
Released in v.1.6.0. Thanks guys!
from react-native-link-preview.
@TPXP @demchenkoalex A simple way to do this would be:
let abortControllerTimeout: NodeJS.Timeout = null;
const abort = new AbortController();
let request = fetch(url, {
headers: {
'User-Agent':
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
},
signal: abort.signal
});
// Abort fetch request after 5 seconds.
abortControllerTimeout = setTimeout(() => {
abort.abort();
}, 5000);
let response = await request;
clearTimeout(abortControllerTimeout);
Ofcourse the timeout can be modified. I think 5 seconds is enough for a normal request to fetch data but it can be more in case of very slow connections.
from react-native-link-preview.
hey @ammarahm-ed please do, thank you! :)
from react-native-link-preview.
Hey @TPXP thanks for bringing this up! Just googled this problem and it seems like fetch
is very limited, I don't plan to add huge dependencies like fetch-blob
or something, and the only workaround I found/can think of is adding timeout and break the request if timeout is met. WDYT?
from react-native-link-preview.
Hello, thank you very much for your feedback. I've also looked into it and I confirm fetch
seems a little limited (although I haven't checked the React-Native implementation, but I doubt it implements non-standard features like request cancelling and progress reports).
I'm already using rn-fetch-blob
in my app so adding it would not be an issue for me. Their fetch API supports cancelling requests. I understand your point about app size though, perhaps we can make it an optional dependency and leverage request cancelling if it's present?
If rn-fetch-blob
is not present, a timeout would be a good workaround. (That's how OpenGraphScraper worked)
from react-native-link-preview.
I have updated the example to something that actually works. If you think it's a good solution, i can send a PR.
from react-native-link-preview.
is it possible to know whether or not the request timed out ? currently it's just returning an empty object. Which could be confused with "succeeded but empty"
from react-native-link-preview.
Related Issues (20)
- [🐛] Youtube link preview not working correctly on iOS HOT 2
- Facebook and Twitter posts doesn't return image HOT 1
- Spotify link preview not returning anything HOT 2
- Add loading option HOT 7
- URLs with '@' and other allowed characters are not parsed correctly HOT 6
- Styling HOT 1
- LayoutAnimation: consider including react-native-reanimated HOT 3
- Amazon links don't preview correctly HOT 2
- Request: option to not display the link HOT 4
- Add option to specify user agent for link crawling
- App terminated at specific url (Android issue) HOT 4
- Add option to show/hide URL HOT 1
- Android App Crash on specific link HOT 3
- Feature request - Caching HOT 3
- How to get image and link metadata side by side? HOT 2
- Custom Interface HOT 1
- Module could not be found error in typescript project
- how do i change the text color tho, i can change the container background color but not text color HOT 1
- Prevent opening link and add longPress event HOT 2
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 react-native-link-preview.