Skip to content

Commit

Permalink
Create report-url-change.js
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammedadnanv authored Oct 6, 2024
1 parent 95a56c1 commit 8246a88
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .gpt_engineer/report-url-change.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const loadReportUrlChangeEventListener = () => {
/**
* Listen to URL changes and report them to the parent window
*
* See https://stackoverflow.com/a/46428962
* The Navigation API https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API seemed promising,
* but it is not supported in all major browsers.
*/
const observeUrlChange = () => {
let oldHref = document.location.href;
const body = document.querySelector("body");
const observer = new MutationObserver(() => {
if (oldHref !== document.location.href) {
oldHref = document.location.href;
window.top.postMessage({ type: "URL_CHANGED", url: document.location.href }, "https://run.gptengineer.app");
window.top.postMessage({ type: "URL_CHANGED", url: document.location.href }, "http://localhost:3000");
}
});
observer.observe(body, { childList: true, subtree: true });
};

window.addEventListener("load", observeUrlChange);
};

0 comments on commit 8246a88

Please sign in to comment.