Skip to content

Commit

Permalink
feat(core): browserless session
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Mar 17, 2022
1 parent 5cb3c92 commit 0de6846
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/lib/ScriptInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class ScriptInstance {
constructor() {
this.mode = process.env.NODE_ENV as any;
if (
!['development', 'production', 'multiverse', 'timetravel', 'background'].includes(this.mode)
!['development', 'production', 'multiverse', 'timetravel', 'browserless'].includes(this.mode)
) {
this.mode = 'development';
}
Expand Down
2 changes: 1 addition & 1 deletion core/connections/ConnectionToClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default class ConnectionToClient
session.once('closing', () => this.sessionIdToRemoteEvents.delete(sessionId));
session.once('closed', this.checkForAutoShutdown);
}
return { tabId: tab.id, sessionId: session.id, frameId: tab.mainFrameId };
return { tabId: tab?.id, sessionId: session.id, frameId: tab?.mainFrameId };
}

/////// INTERNAL FUNCTIONS /////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions core/lib/GlobalPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export default class GlobalPool {
const session = new Session(options);
this.events.emit('session-created', { session });

if (session.mode === 'browserless') return session;

const puppet = await this.getPuppet(session.plugins, session.browserEngine);

if (disableMitm !== true) {
Expand Down
1 change: 1 addition & 0 deletions core/lib/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export default class Session
}

public async createTab(): Promise<Tab> {
if (this.mode === 'browserless') return null;
const page = await this.newPage({ groupName: 'session' });

// if first tab, install session storage
Expand Down
2 changes: 1 addition & 1 deletion interfaces/ISessionCreateOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default interface ISessionCreateOptions extends ISessionOptions {
startNavigationId?: number;
};
browserEmulatorId?: string;
mode?: 'development' | 'multiverse' | 'production' | 'timetravel' | 'background';
mode?: 'development' | 'multiverse' | 'production' | 'timetravel' | 'browserless';
userAgent?: string;
scriptInstanceMeta?: IScriptInstanceMeta;
userProfile?: IUserProfile;
Expand Down

0 comments on commit 0de6846

Please sign in to comment.