diff --git a/.gpt_engineer/get-user-snapshot.js b/.gpt_engineer/get-user-snapshot.js deleted file mode 100644 index a1cca98..0000000 --- a/.gpt_engineer/get-user-snapshot.js +++ /dev/null @@ -1,10 +0,0 @@ -import { toPng } from "html-to-image"; - -export const loadGetUserSnapshotEventListener = () => { - window.addEventListener("blur", () => { - toPng(document.body).then((url) => { - window.top.postMessage({ type: "USER_SNAPSHOT", snapshot: url }, "http://localhost:3000"); - window.top.postMessage({ type: "USER_SNAPSHOT", snapshot: url }, "https://gptengineer.app"); - }); - }); -}; diff --git a/.gpt_engineer/index.js b/.gpt_engineer/index.js deleted file mode 100644 index 86a1afa..0000000 --- a/.gpt_engineer/index.js +++ /dev/null @@ -1,14 +0,0 @@ -import { loadGetUserSnapshotEventListener } from "./get-user-snapshot"; -import { loadReportUrlChangeEventListener } from "./report-url-change"; -import { loadReportErrorEventListener } from "./report-error"; - -const main = () => { - if (window.top === window.self) { - return; - } - loadGetUserSnapshotEventListener(); - loadReportUrlChangeEventListener(); - loadReportErrorEventListener(); -}; - -main(); diff --git a/.gpt_engineer/report-error.js b/.gpt_engineer/report-error.js deleted file mode 100644 index fff80c4..0000000 --- a/.gpt_engineer/report-error.js +++ /dev/null @@ -1,132 +0,0 @@ -const postMessage = (message) => { - window.top.postMessage(message, "https://gptengineer.app"); - window.top.postMessage(message, "http://localhost:3000"); -}; - -const patchFetch = (reportHTTPError) => { - // Save the original fetch function - const originalFetch = window.fetch; - - window.fetch = async function (...args) { - try { - // Call the original fetch function - const response = await originalFetch(...args); - - // Optionally, check for errors or log them - if (!response.ok) { - const body = response?.text ? await response.text() : undefined; - reportHTTPError("non_200_response", { - ...response, - status: response.status, - url: args?.[0] || response.url, - body, - method: args?.[1]?.method || "GET", - origin: window.location.origin, - }); - } - - return response; - } catch (error) { - // Handle any other fetch errors (e.g., network issues) - reportHTTPError("fetch_error", { - message: error?.message, - stack: error?.stack, - url: args?.[0], - method: args?.[1]?.method || "GET", - origin: window.location.origin, - }); - throw error; - } - }; -}; - -export const loadReportErrorEventListener = (() => { - let isInitialized = false; - - const extractError = ({ message, lineno, colno, filename, error }) => { - return { message, lineno, colno, filename, stack: error?.stack }; - }; - - return () => { - if (isInitialized) return; - - const reportedErrors = new Set(); - - const generateErrorId = (event) => { - const { lineno, colno, filename, message } = event; - return `${message}|${filename}|${lineno}|${colno}`; - }; - - const reportHTTPError = async (type, response) => { - if (type === "non_200_response") { - postMessage({ - type: "FETCH_ERROR", - error: { - message: `failed to call url ${response.url} with status ${response.status} and statusText ${response.statusText}`, - status: response.status, - statusText: response.statusText, - url: response.url, - body: response.body, - }, - }); - } else if (type === "fetch_error") { - postMessage({ - type: "FETCH_ERROR", - error: response, - }); - } - }; - - patchFetch(reportHTTPError); - - const isErrorAlreadyReported = (errorId) => { - if (reportedErrors.has(errorId)) { - return true; - } - reportedErrors.add(errorId); - // Optionally, clear the set after some time to prevent it from growing indefinitely - setTimeout(() => reportedErrors.delete(errorId), 5000); - return false; - }; - - const reportError = (event) => { - const errorId = generateErrorId(event); - - // Prevent error being reported multiple times - if (isErrorAlreadyReported(errorId)) { - return; - } - - const error = extractError(event); - - postMessage({ type: "RUNTIME_ERROR", error }); - }; - - // Listen to runtime errors and report them to the parent window - window.addEventListener("error", reportError); - - // Listen to unhandled promise rejections - window.addEventListener("unhandledrejection", (event) => { - if (!event.reason?.stack) { - return; - } - - const errorId = - event.reason?.stack || event.reason?.message || String(event.reason); - - // Prevent error being reported multiple times - if (isErrorAlreadyReported(errorId)) { - return; - } - - const error = { - message: event.reason?.message || "Unhandled promise rejection", - stack: event.reason?.stack || String(event.reason), - }; - - postMessage({ type: "UNHANDLED_PROMISE_REJECTION", error }); - }); - - isInitialized = true; - }; -})(); diff --git a/.gpt_engineer/report-url-change.js b/.gpt_engineer/report-url-change.js deleted file mode 100644 index f842f39..0000000 --- a/.gpt_engineer/report-url-change.js +++ /dev/null @@ -1,23 +0,0 @@ -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); -};