mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-27 19:25:15 +02:00
feat(desktop): emit PostHog events for OAuth redirect intercept and miss
Adds two diagnostic events to surface OAuth-redirect failures we can't reproduce on Linux: - desktop_oauth_redirect_intercepted fires from inside onBeforeRequest with the original host, path, and target port — confirms the rewrite actually ran. - desktop_oauth_redirect_missed fires from a read-only onCompleted listener when a /dashboard/*/connectors/callback URL lands off-localhost, meaning the rewrite filter didn't catch it. This is the smoking-gun event for "connector OAuth dies on mac/win" reports. Read-only; no behavior change.
This commit is contained in:
parent
1b6c238c68
commit
b9403b1720
1 changed files with 25 additions and 0 deletions
|
|
@ -83,8 +83,14 @@ export function createMainWindow(initialPath = '/dashboard'): BrowserWindow {
|
||||||
session.defaultSession.webRequest.onBeforeRequest(rewriteFilter, (details, callback) => {
|
session.defaultSession.webRequest.onBeforeRequest(rewriteFilter, (details, callback) => {
|
||||||
try {
|
try {
|
||||||
const u = new URL(details.url);
|
const u = new URL(details.url);
|
||||||
|
const originalHost = u.host;
|
||||||
u.protocol = 'http:';
|
u.protocol = 'http:';
|
||||||
u.host = `localhost:${getServerPort()}`;
|
u.host = `localhost:${getServerPort()}`;
|
||||||
|
trackEvent('desktop_oauth_redirect_intercepted', {
|
||||||
|
host: originalHost,
|
||||||
|
path: u.pathname,
|
||||||
|
rewritten_to_port: getServerPort(),
|
||||||
|
});
|
||||||
callback({ redirectURL: u.toString() });
|
callback({ redirectURL: u.toString() });
|
||||||
} catch {
|
} catch {
|
||||||
callback({});
|
callback({});
|
||||||
|
|
@ -92,6 +98,25 @@ export function createMainWindow(initialPath = '/dashboard'): BrowserWindow {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Diagnostic: connector callback landing somewhere other than localhost
|
||||||
|
// means the rewrite missed and the user is stranded off-app.
|
||||||
|
session.defaultSession.webRequest.onCompleted(
|
||||||
|
{ urls: ['*://*/dashboard/*/connectors/callback*'] },
|
||||||
|
(details) => {
|
||||||
|
try {
|
||||||
|
const u = new URL(details.url);
|
||||||
|
if (u.hostname === 'localhost' || u.hostname === '127.0.0.1') return;
|
||||||
|
trackEvent('desktop_oauth_redirect_missed', {
|
||||||
|
host: u.host,
|
||||||
|
path: u.pathname,
|
||||||
|
status_code: details.statusCode,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// ignore malformed URLs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
mainWindow.webContents.on('did-fail-load', (_event, errorCode, errorDescription, validatedURL) => {
|
mainWindow.webContents.on('did-fail-load', (_event, errorCode, errorDescription, validatedURL) => {
|
||||||
console.error(`Failed to load ${validatedURL}: ${errorDescription} (${errorCode})`);
|
console.error(`Failed to load ${validatedURL}: ${errorDescription} (${errorCode})`);
|
||||||
if (errorCode === -3) return;
|
if (errorCode === -3) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue