-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onShouldStartLoadWithRequest not working consistently across different platforms #381
Comments
Feel free to submit a PR cc @maxammann |
@Titozzz willingly , i tried couple of times, but i could not make it work , i walked thought this repo and followed the implementation of shouldOverrideUrlLoading ,no avail. for most of the steps , i was justing shooting in the dark , i have zero experience of mobile development . sorry~ |
Ios and android methods don't work in a same way. Ios methods are asynchronous, android are synchronous. So I believe that Unfortunately that's not only bad news. |
@punksta thanks, i added the shouldInterceptRequest to Android side, and was able to intercept and dispatch the event to React side on my emulator(Pixel_API_23), but i found it's quiet different from shouldOverrideUrlLoading , it intercepts every request(css/js/font/....),so there will be a lot frequent data communication between the Native side and React Side . does it raise performance concern ? i see that current shouldOverrideUrlLoading implementation is just reject loading and handle the request url to React side , calling loadUrl method when TRUE return from React Side. i found ServiceWorkerClient seems relevant , but it is overwhelming to me , and it says "added in API level 24" . |
shouldOverrideUrlLoading and shouldInterceptRequest are doing different things which should be handled in react-native. shouldInterceptRequest is working on individual http requests which is currently not implemented in react-native. shouldOverrideUrlLoading kind of handles "clicks". The behaviour of onShouldStartLoadWithRequest is inconsitent during the loading of the webview. I'm currently using this to work around this issue:
(I'm feeding html directly to the webview, therefore I'm using I don't have time currently to make the calling consistent but this should be tackled some day 📦 This is just way to confusing to know what is happening behind the scenes. |
@maxammann I am using shouldInterceptRequest method to filter specific request on Android now, cuz my use case does not really need to intercept any request, just need to inform the react side which request is being made , the current shouldOverrideUrlLoading method on Android is not able to capture iframe(verified) and Ajax request . I do hope shouldInterceptRequest method could be implemented somehow ,but I am not experienced of Native mobile development, so it is beyond my reach due to what I found from my previous comments . |
I'm having a problem with I'm using function onShouldStartLoadWithRequest(request) {
Linking.openURL(request.url)
.catch(err => console.error(`Could not open URL ${request.url}`, err));
return false;
} My problem is that on iOS this function gets called for embedded Youtube videos, which I believe are iframes. On Android, this function is only called when the user taps on something. I'd prefer |
Hey folks, https://github.com/kulbhushan-ucreate/react-native-web-view. |
@ericlathrop I want the same thing, did you manage to make it work? I only want to intercept what would be changes to the |
@gfpacheco I ended up writing a blacklist of URL prefixes to ignore. Far from ideal. At least I stored the blacklist in Firebase so I can update it without having to push a new version of my app. |
Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically |
@ericlathrop , were you able to solve it? Could you assist me? I have this implementation:
So |
@ldco2016 I am having the same issue. Were you able to solve in anyways? Can Someone please help. |
@ldco2016 @2xSamurai Here's my workaround for this issue: const webViewAllowedEmbeddingUrlPrefixes = [
"https://m.facebook.com/plugins/video.php",
"https://platform.twitter.com/jot.html",
"https://syndication.twitter.com/i/jot",
"https://www.facebook.com/plugins/video.php",
"https://www.scribd.com/embeds/",
"https://www.youtube.com/embed/",
];
const webViewAllowedEmbeddingUrlRegexes = [
"https://www.iheart.com/podcast/.*\\?embed=true"
];
const webViewRestrictedEmbeddingUrlPrefixes = [
"https://accounts.google.com/o/oauth2/iframe",
"https://clearchannel.demdex.net/",
"https://staticxx.facebook.com/connect/",
"https://synchroscript.deliveryengine.adswizz.com/",
"https://www.facebook.com/connect/",
];
function onShouldStartLoadWithRequest(request) {
if (request.url === "about:blank") {
return true;
}
// HACK: allow some urls to be embedded, and reject others
// https://github.com/react-native-community/react-native-webview/issues/381
if (Platform.OS === 'ios') {
if (webViewAllowedEmbeddingUrlPrefixes.some(prefix => request.url.indexOf(prefix) === 0)) {
return true;
}
if (webViewAllowedEmbeddingUrlRegexes.map(r => new RegExp(r)).some(regexp => request.url.match(regexp) !== null)) {
return true;
}
if (webViewRestrictedEmbeddingUrlPrefixes.some(prefix => request.url.indexOf(prefix) === 0)) {
return false;
}
}
Linking.openURL(request.url)
.catch(err => console.error(`Could not open URL ${request.url}`, err));
return false;
} |
Have the same issue with the Youtube iframe player being catched with onShouldStartLoadWithRequest() on iOS |
Can I ask, how did you expose |
Any solution |
Any solution to intercept internal api calls |
+1 |
Same question, how we can expose |
I discover the I'm using it that way :
|
"react": "16.6.3", "react-native": "0.58.5", "react-native-webview": "^5.2.1"
on iOS : onShouldStartLoadWithRequest event fires 3 TIMEs with 3 different URLs
on Android: onShouldStartLoadWithRequest event fires 1 TIME with 1 URL
async requests/iframe ignored on android ?
UPDATE:
i did a little research , found this https://stackoverflow.com/questions/26651586/difference-between-shouldoverrideurlloading-and-shouldinterceptrequest/26652169
may be we should use shouldInterceptRequest method instead of shouldOverrideUrlLoading on Android , since it captures all request(css/script/iframe/ajax...), make it more consistent with iOS behavior ?
The text was updated successfully, but these errors were encountered: