Skip to content

Instantly share code, notes, and snippets.

@t-wy
Created November 28, 2022 12:22
Show Gist options
  • Save t-wy/66faed8679d127793891ecb775efdaa9 to your computer and use it in GitHub Desktop.
Save t-wy/66faed8679d127793891ecb775efdaa9 to your computer and use it in GitHub Desktop.
Get Facebook canonical Post ID (share URL) without pfbid parameter
javascript: fbid = /share_fbid":"(\d+)"/g.exec([...document.getElementsByTagName("script")].filter(x => x.innerHTML.includes("share_fbid"))[0].innerHTML)[1]; alert(location.href.split("/").slice(0, -1).join("/") + "/" + fbid);
// can be used in console / bookmark / address bar (remember to add back javascript if the browser strips it automatically)
@gcobc12632
Copy link

is it still works?

@t-wy
Copy link
Author

t-wy commented Aug 13, 2024

is it still works?

@gcobc12632 Facebook has created several URL formats since then. Some URL still keeps the ID, and for those looking like https://lp7vsba6mm.proxynodejs.usequeue.com/.../posts/pfbid..., the post ID can no longer be found in any element.

However you may still try to create an embed via "…" at the top-right corner of the post or through https://uoj1eqlz6p.proxynodejs.usequeue.com/docs/plugins/embedded-posts/. The hyperlink tied to the Facebook logo at the top right corner should still be pointing to the URL with the original ID instead of the post ID.

@hkscsheph
Copy link

  1. Open Inspector
  2. Ctrl+F looks for "share_fbid" in HTML
  3. Get the value of data-content-len="??????"
  4. In console, try
    $x('//*[contains(@data-content-len,??????)]')[0].innerText.match(/share_fbid":"(.+?)",/)[1]
  5. If success, the pfbid can be replaced by this result

@hkscsheph
Copy link

Further simplify~ run the following code in console will copy the shortest link form fb.com/1234567890 to clipboard

copy('fb.com/'+[...document.getElementsByTagName("script")].filter(x => x.innerHTML.includes("share_fbid"))[0].innerText.match(/share_fbid":"(.+?)",/)[1])

@gcobc12632
Copy link

Further simplify~ run the following code in console will copy the shortest link form fb.com/1234567890 to clipboard

copy('fb.com/'+[...document.getElementsByTagName("script")].filter(x => x.innerHTML.includes("share_fbid"))[0].innerText.match(/share_fbid":"(.+?)",/)[1])

amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment