fix: keep Browser iframe in sync with url bar on page changes
This commit is contained in:
parent
cf826dce82
commit
b4ae99b74c
|
@ -5,6 +5,7 @@ import {
|
||||||
useCallback,
|
useCallback,
|
||||||
useContext,
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import {
|
import {
|
||||||
|
@ -179,16 +180,31 @@ export function Navigator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Browser() {
|
export function Browser() {
|
||||||
const { url } = useBrowserState();
|
const { url, setUrl } = useBrowserState();
|
||||||
const status = useLumeStatus();
|
const status = useLumeStatus();
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
boot(status, auth);
|
boot(status, auth);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleIframeLoad = () => {
|
||||||
|
try {
|
||||||
|
const newUrl = iframeRef?.current?.contentWindow?.location.href as string;
|
||||||
|
setUrl(newUrl);
|
||||||
|
} catch (e) {
|
||||||
|
// This will catch errors related to cross-origin requests, in which case we can't access the iframe's contentWindow.location
|
||||||
|
console.warn(
|
||||||
|
"Couldn't access iframe URL due to cross-origin restrictions:",
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<iframe
|
<iframe
|
||||||
|
onLoad={handleIframeLoad}
|
||||||
src={url ? `/browse/${url}` : "about:blank"}
|
src={url ? `/browse/${url}` : "about:blank"}
|
||||||
className="w-full h-full"
|
className="w-full h-full"
|
||||||
></iframe>
|
></iframe>
|
||||||
|
|
Loading…
Reference in New Issue