Simply put:
I need to know the websiteId in my outside (extension) scope.
So, where i have alert(websiteId)
i would ideally run setWebsiteId(websiteId)
but i know this is not possible as i cannot pass functions as args
to the func of executeScript.
export const ExtensionPopup = ({ tab }) => {
const [websiteId, setWebsiteId] = useState(null);
useEffect(() => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
args: [],
func: () => {
const script = document.getElementById('pertentoScript');
const url = new URL(script.src);
const websiteId = url.searchParams.get('website-id');
alert(websiteId);
},
});
}, []);
return <div></div>
}
I’m new to Chrome extensions, and can’t find the proper documentation for this.