I am trying to block content in a react-native web view using the onShouldStartLoadWithRequest function. I use async functions for the engine that decides whether or not to block a specific request. Since I am using an async function to load the engine and need to return a boolean to the onShouldStartLoadWithRequest function, I ended up using the .then method to pass the engine variable to my function that uses it. However, when I test this out, no requests are getting blocked. I tried logging the code ran in the .then method in the console to see what is going on and I did end up getting a boolean. However, when I tried another random async function that always returns false(it will always block content), that didn't work either(with a normal function it did work), so I feel like I am not handling the async functions correctly somehow. Here is my applicable code. In the end I am trying to return a boolean, is that not what is happening in the onShouldStartLoadWithRequest function?
//This is my loading function - it is located outside of the onShouldStartLoadWithRequest function
async function loadEngine() {
let engine = await FiltersEngine.fromPrebuiltAdsAndTracking(fetch);
return engine
}
//This is my onShouldStartLoadWithRequest function
onShouldStartLoadWithRequest={(WebViewRequest) => {
function useEngine(requestURLS, engine) {
const {
match
} = engine.match(Request.fromRawDetails({
url: requestURLS,
}))
let final_output;
final_output = !match
return final_output
}
return loadEngine().then((engine) => (useEngine(WebViewRequest.url, engine)))
}}