wip
This commit is contained in:
@@ -164,9 +164,12 @@ export class PlaywrightAuthSessionService implements IAuthenticationService {
|
||||
|
||||
async initiateLogin(): Promise<Result<void>> {
|
||||
try {
|
||||
this.log('info', 'Opening login in Playwright browser');
|
||||
const forceHeaded = true;
|
||||
this.log('info', 'Opening login in headed Playwright browser (forceHeaded=true)', {
|
||||
forceHeaded,
|
||||
});
|
||||
|
||||
const connectResult = await this.browserSession.connect();
|
||||
const connectResult = await this.browserSession.connect(forceHeaded);
|
||||
if (!connectResult.success) {
|
||||
return Result.err(new Error(connectResult.error || 'Failed to connect browser'));
|
||||
}
|
||||
@@ -183,7 +186,9 @@ export class PlaywrightAuthSessionService implements IAuthenticationService {
|
||||
timeout: this.navigationTimeoutMs,
|
||||
});
|
||||
|
||||
this.log('info', 'Browser opened to login page, waiting for login...');
|
||||
this.log('info', forceHeaded
|
||||
? 'Browser opened to login page in headed mode, waiting for login...'
|
||||
: 'Browser opened to login page, waiting for login...');
|
||||
this.authState = AuthenticationState.UNKNOWN;
|
||||
|
||||
const loginSuccess = await this.authFlow.waitForPostLoginRedirect(
|
||||
@@ -219,7 +224,6 @@ export class PlaywrightAuthSessionService implements IAuthenticationService {
|
||||
try {
|
||||
await this.browserSession.disconnect();
|
||||
} catch {
|
||||
// ignore cleanup errors
|
||||
}
|
||||
|
||||
return Result.err(error instanceof Error ? error : new Error(message));
|
||||
@@ -370,9 +374,9 @@ export class PlaywrightAuthSessionService implements IAuthenticationService {
|
||||
cookieResult.unwrap() === AuthenticationState.AUTHENTICATED;
|
||||
|
||||
const pageAuthenticated =
|
||||
(isOnAuthenticatedPath && !isOnLoginPath && cookiesValid) ||
|
||||
hasAuthUI ||
|
||||
(!hasLoginUI && !isOnLoginPath);
|
||||
!hasLoginUI &&
|
||||
!isOnLoginPath &&
|
||||
((isOnAuthenticatedPath && cookiesValid) || hasAuthUI);
|
||||
|
||||
this.log('debug', 'Page authentication check', {
|
||||
url,
|
||||
|
||||
@@ -90,8 +90,23 @@ export class PlaywrightBrowserSession {
|
||||
|
||||
async connect(forceHeaded: boolean = false): Promise<{ success: boolean; error?: string }> {
|
||||
if (this.connected && this.page) {
|
||||
this.log('debug', 'Already connected, reusing existing connection');
|
||||
return { success: true };
|
||||
const shouldReuse =
|
||||
!forceHeaded ||
|
||||
this.actualBrowserMode === 'headed';
|
||||
|
||||
if (shouldReuse) {
|
||||
this.log('debug', 'Already connected, reusing existing connection', {
|
||||
browserMode: this.actualBrowserMode,
|
||||
forcedHeaded: forceHeaded,
|
||||
});
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
this.log('info', 'Existing browser connection is headless, reopening in headed mode for login', {
|
||||
browserMode: this.actualBrowserMode,
|
||||
forcedHeaded: forceHeaded,
|
||||
});
|
||||
await this.closeBrowserContext();
|
||||
}
|
||||
|
||||
if (this.isConnecting) {
|
||||
|
||||
Reference in New Issue
Block a user