Created
February 20, 2025 09:23
-
-
Save MahbbRah/8529f35bc89ab00cc6df0e8d60973874 to your computer and use it in GitHub Desktop.
These methods returns the audio source URL from Facebook messenger react component.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getReactFiber(node) { | |
for (const key in node) { | |
if (key.startsWith("__reactFiber$")) { | |
return node[key]; | |
} | |
} | |
return null; | |
} | |
function findAudioSource(node) { | |
const fiber = getReactFiber(node); | |
if (!fiber) return null; | |
let current = fiber; | |
while (current) { | |
if (current.memoizedProps && current.memoizedProps.audioEl) { | |
return current.memoizedProps.audioEl.current.src; // Extract audio source URL | |
} | |
current = current.return; // Traverse up the React tree | |
} | |
return null; | |
} | |
// Run the function on the selected element in the Elements tab | |
console.log(findAudioSource($selectedElement)); |
Just to publish it over here
The reason it doesn't work inside chrome extension is because the scripts executes inside a isolated environment which doesn't have access to React Fiber and all that data.
by research, we found a way to inject the code directly into the browser context instead of an isolated environment
const script = document.createElement("script");
script.src = chrome.runtime.getURL("inject.js"); // ✅ Ensure correct path
script.onload = function () {
this.remove(); // ✅ Cleanup after execution
};
document.documentElement.appendChild(script);
the solution should be wrapped in an IIFE method with the file named inject.js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following doesn't work in chrome extension.
It can't find react fiber in the page.