javascript - Deeplink to Facebook App (using fb: protocol) not working from Facebook in-app browser - Stack Overflow

I am writing a mobile web page which has both a redirect and two manual backup links (for when the redi

I am writing a mobile web page which has both a redirect and two manual backup links (for when the redirect doesn't work) to a Facebook Page.

The link takes the form:

fb://page/[PAGE ID NUMBER]

The redirect and link work in Chrome Mobile and Firefox Mobile but (surprise) they don't work in Facebook Browser which, instead, gives me the error:

Page can't be loaded.

I am perplexed that a link to the Facebook App doesn't work from within the Facebook Browser.

How can I resolve this? Are there any creative solutions or workarounds... or have I missed something obvious?


Additional Info: It looks like the redirect is working in at least one version of the Facebook Browser on the Facebook iOS App. So the issue may be isolated to the Facebook Android App.


UPDATE 1

I've made some progress. I've discovered that Facebook's in-app browser doesn't always (or doesn't ever?) acknowledge / load / execute external script files.

Added: (To find out why not, see Update 8, below...)

In this case the href attributes in the links were being re-populated with fb:// protocol links by an external script after page load.

I have moved the relevant javascript functions from the external script to the bottom of the actual page. I have tested the functions and I can see they are now activating. Although the links still don't work.


UPDATE 2

It struck me that there may be some security mechanism going on behind the scenes which doesn't allow for any javascript-driven re-population of href attributes and that instead of the fb:// protocol links not working, it was maybe the case that the initial, default / links were never even being replaced and it was those http:// protocol links that weren't working.

So I updated the PHP template, so that the initial default links were the fb:// instead of the http:// links (so nothing in the page delivered to the Facebook in-app browser would need to be updated by any client-side script at all at any point).

Nope. Still not working.


UPDATE 3

I added a plain vanilla link to the bottom of the page, linking to the site's homepage. The link functioned entirely normally.

Later, I pointed the original links to an external domain. They didn't work.

So... I concluded that only http:// protocol links to the same domain would work and that's why the links wouldn't work if they pointed to an external domain or to an fb:// protocol address.

Wrong conclusion.

I pointed the original links at the site's homepage and they still didn't work.


UPDATE 4

In a moment of inspiration, I removed the reference to the external script which I'd set up to customise the links to the OS + browser environment (even though this script reference was being entirely ignored by Facebook, according to the FB Debugging tool.

The links worked.

So the reason why the plain vanilla link I had added earlier had worked, was nothing to do with where it was pointing and simply to do with the fact that at no point had a script tried to access it or update it.

Added: (This isn't the reason. See Update 8, below...)

I pointed the original links at the external domain. They worked.

I pointed the original links at the fb:// protocol. They didn't work.


UPDATE 5

Now that I've got rid of the external script reference, I can point the original protocol links at any http:// protocol address and they work.

Including the web equivalent of the page I am trying to open in the Facebook App.

Let's review that:

The Facebook website is opening in the Facebook in-app browser.

I know, right?


UPDATE 6 [.HTACCESS REDIRECT]

I changed the link destination to /fb-custom-redirect/.

Then I added a line to the mod_rewrite section of my .htaccess file:

RewriteRule ^fb-custom-redirect fb://page/[PAGE ID NUMBER]

Naturally the server didn't understand what I was asking for.


UPDATE 7 [PHP REDIRECT]

I created an index.php for /fb-custom-redirect/ and added the following:

<?php
header('Location: fb://page/[PAGE ID NUMBER]');
?>

Guess what? This works in Firefox Mobile. It also works in Chrome Mobile.

But in the Facebook in-app browser, it returns the same error:

Page can't be loaded.

UPDATE 8

I've only just discovered - and this is not insignificant - that when the Facebook Debugger Tool (/) refreshes Facebook's cache of a given page, it only refreshes the .html.

Pressing Scrape Again does not refresh any external resources like .css and .js files.

Instead Facebook continues to refer to its own cached versions of those files, regardless that the .html file cache has just been updated.

The workaround (in PHP, at least) is to append the filepath with a new, randomly generated query string every time the page is loaded:

<link rel="stylesheet" href="/styles/mystyles.css?'.uniqid().'" />

Now the Facebook in-app browser is fetching up-to-date versions of my .css and .js files.

This explains my initial observation in Update 1:

I've made some progress. I've discovered that Facebook's in-app browser doesn't always (or doesn't ever?) acknowledge / load / execute external script files.

I'm going to conclude that the Facebook in-app browser was parsing the external .js file reference every time, but it was repeatedly accessing an old, cached version of that file.


Nevertheless, even after all the hypotheses and experimenting above, I'm still no closer to discovering why fb: protocol deeplinks don't work in the Facebook App's in-app browser.

I give up.

I am writing a mobile web page which has both a redirect and two manual backup links (for when the redirect doesn't work) to a Facebook Page.

The link takes the form:

fb://page/[PAGE ID NUMBER]

The redirect and link work in Chrome Mobile and Firefox Mobile but (surprise) they don't work in Facebook Browser which, instead, gives me the error:

Page can't be loaded.

I am perplexed that a link to the Facebook App doesn't work from within the Facebook Browser.

How can I resolve this? Are there any creative solutions or workarounds... or have I missed something obvious?


Additional Info: It looks like the redirect is working in at least one version of the Facebook Browser on the Facebook iOS App. So the issue may be isolated to the Facebook Android App.


UPDATE 1

I've made some progress. I've discovered that Facebook's in-app browser doesn't always (or doesn't ever?) acknowledge / load / execute external script files.

Added: (To find out why not, see Update 8, below...)

In this case the href attributes in the links were being re-populated with fb:// protocol links by an external script after page load.

I have moved the relevant javascript functions from the external script to the bottom of the actual page. I have tested the functions and I can see they are now activating. Although the links still don't work.


UPDATE 2

It struck me that there may be some security mechanism going on behind the scenes which doesn't allow for any javascript-driven re-population of href attributes and that instead of the fb:// protocol links not working, it was maybe the case that the initial, default http://www.facebook./ links were never even being replaced and it was those http:// protocol links that weren't working.

So I updated the PHP template, so that the initial default links were the fb:// instead of the http:// links (so nothing in the page delivered to the Facebook in-app browser would need to be updated by any client-side script at all at any point).

Nope. Still not working.


UPDATE 3

I added a plain vanilla link to the bottom of the page, linking to the site's homepage. The link functioned entirely normally.

Later, I pointed the original links to an external domain. They didn't work.

So... I concluded that only http:// protocol links to the same domain would work and that's why the links wouldn't work if they pointed to an external domain or to an fb:// protocol address.

Wrong conclusion.

I pointed the original links at the site's homepage and they still didn't work.


UPDATE 4

In a moment of inspiration, I removed the reference to the external script which I'd set up to customise the links to the OS + browser environment (even though this script reference was being entirely ignored by Facebook, according to the FB Debugging tool.

The links worked.

So the reason why the plain vanilla link I had added earlier had worked, was nothing to do with where it was pointing and simply to do with the fact that at no point had a script tried to access it or update it.

Added: (This isn't the reason. See Update 8, below...)

I pointed the original links at the external domain. They worked.

I pointed the original links at the fb:// protocol. They didn't work.


UPDATE 5

Now that I've got rid of the external script reference, I can point the original protocol links at any http:// protocol address and they work.

Including the http://www.facebook. web equivalent of the page I am trying to open in the Facebook App.

Let's review that:

The Facebook website is opening in the Facebook in-app browser.

I know, right?


UPDATE 6 [.HTACCESS REDIRECT]

I changed the link destination to /fb-custom-redirect/.

Then I added a line to the mod_rewrite section of my .htaccess file:

RewriteRule ^fb-custom-redirect fb://page/[PAGE ID NUMBER]

Naturally the server didn't understand what I was asking for.


UPDATE 7 [PHP REDIRECT]

I created an index.php for /fb-custom-redirect/ and added the following:

<?php
header('Location: fb://page/[PAGE ID NUMBER]');
?>

Guess what? This works in Firefox Mobile. It also works in Chrome Mobile.

But in the Facebook in-app browser, it returns the same error:

Page can't be loaded.

UPDATE 8

I've only just discovered - and this is not insignificant - that when the Facebook Debugger Tool (https://developers.facebook./tools/debug/sharing/) refreshes Facebook's cache of a given page, it only refreshes the .html.

Pressing Scrape Again does not refresh any external resources like .css and .js files.

Instead Facebook continues to refer to its own cached versions of those files, regardless that the .html file cache has just been updated.

The workaround (in PHP, at least) is to append the filepath with a new, randomly generated query string every time the page is loaded:

<link rel="stylesheet" href="/styles/mystyles.css?'.uniqid().'" />

Now the Facebook in-app browser is fetching up-to-date versions of my .css and .js files.

This explains my initial observation in Update 1:

I've made some progress. I've discovered that Facebook's in-app browser doesn't always (or doesn't ever?) acknowledge / load / execute external script files.

I'm going to conclude that the Facebook in-app browser was parsing the external .js file reference every time, but it was repeatedly accessing an old, cached version of that file.


Nevertheless, even after all the hypotheses and experimenting above, I'm still no closer to discovering why fb: protocol deeplinks don't work in the Facebook App's in-app browser.

I give up.

Share Improve this question edited Nov 25, 2020 at 23:19 Rounin asked Aug 19, 2019 at 11:11 RouninRounin 29.6k13 gold badges98 silver badges123 bronze badges 12
  • One possible solution might be to detect the Facebook in-app browser (using if (navigator.userAgent.indexOf('FBAV') > -1) {...}) and then re-open the same page in the external browser, but I'm not even sure if this is possible...? – Rounin Commented Aug 19, 2019 at 15:22
  • 2 Where is update 9 ? – Accountant م Commented Aug 27, 2019 at 5:29
  • 1 @Tuckbros No this question is not a dupe for the link, OP asks about facebook in-app browser only why it still using the cached versions. – Accountant م Commented Aug 27, 2019 at 19:48
  • 1 @Accountantم - Hah. Nice one. Update 9 is (currently) "I've practically given up. I literally cannot believe that the Facebook in-app browser can display pages from the Facebook website but doesn't automatically send the user to the equivalent address in the actual app, which is the user is obviously already using, by virtue of having the in-app browser open." – Rounin Commented Aug 27, 2019 at 21:18
  • 1 you can also try with a different header in your update 7. ref : en.wikipedia/wiki/URL_redirection#HTTP_status_codes_3xx and php/manual/en/function.header.php to force a "303" http response. – Tuckbros Commented Aug 27, 2019 at 22:01
 |  Show 7 more ments

1 Answer 1

Reset to default 2

Apple apps are sandboxed. This means they cannot access other apps and execute code. Facebook is running a browsing instance and when you try to call the fb:// protocol, the iPhone is blocking you from doing this to try to create an infinite app loading loop. I.e, you open a page in FB browser and it opens itself in FB browser and it opens itself in FB browser...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744785618a4593606.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信