'JavaScript triggered redirect not working on site opened in facebook webview

Opening our ecommerce site from within the Facebook app on Android, opens the page itself in a Facebook web view. When performing the purchase, an external app is opened for digital identification, and the user then has to return to the Facebook web view. Upon returning to Facebook - the user should be redirected to a thank you page.

This works fine in iOS. However - in some Android phones this doesn't work. The hypothesis is that the Facebook web view blocks programmatically initiated redirects, since putting the url in a link clicked by the user works fine.

The issue is recreated in Pixel with Android 12 and Facebook app, however the redirect works in some other web view apps on the same phone making Facebook app a suspect.

Different redirect approaches that has been tested with and without delays:

//1
document.location = url;

//2
window.location.replace(url);

//3
window.location.href = url;

//4
window.top.location.replace(url);

//5
window.location.replace(url);
window.location.reload();

//6
window.top.location.href = url;
window.open(url);

//7
if (!!(window.history && history.replaceState)) {
    window.history.replaceState(
        {},
        "a title",
        url
    );
}

//8
document.location = url;
document.location.reload()

None of them seems to work. Are there any other suggestions on how to solve this? Much appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source