Files
YouTube.js/docs/api/classes/Session.md
Luan 25d0876b91 refactor(Player)!: Use AST-based JS extraction with side-effect safe code emission (#1052)
* chore(deps): Add `meriyah`

* feat(utils): Implement AST-based JS extractors

* chore(utils): Remove old ast walker code

* fix(Player): Migrate js extraction logic

* chore(JsExtractor): Fix typo in tsdoc

* perf(JsAnalyzer): Simplify main AST analysis logic

* fix(JsAnalyzer): Change `break` to `return` in AST matching logic

* chore: Update docs

* chore: Don't export `PlayerInitializationOptions`

* chore(evaluate): Update error message to include doc link

* perf: Use a `for-loop` to find iife
2025-10-12 09:08:51 -03:00

15 KiB

youtubei.js / Session

Class: Session

Represents an InnerTube session. This holds all the data needed to make requests to YouTube.

Extends

Constructors

new Session()

new Session(context, api_key, api_version, account_index, config_data?, player?, cookie?, fetch?, cache?, po_token?): Session

Parameters

context: Context

api_key: string

api_version: string

account_index: number

config_data?: string

player?: Player

cookie?: string

fetch?

cache?: ICache

po_token?: string

Returns

Session

Overrides

EventEmitter.constructor

Defined in

src/core/Session.ts:258

Properties

account_index

account_index: number

Defined in

src/core/Session.ts:262


actions

actions: Actions

Defined in

src/core/Session.ts:255


api_key

api_key: string

Defined in

src/core/Session.ts:260


api_version

api_version: string

Defined in

src/core/Session.ts:261


cache?

optional cache: ICache

Defined in

src/core/Session.ts:267


config_data?

optional config_data: string

Defined in

src/core/Session.ts:263


context

context: Context

Defined in

src/core/Session.ts:259


optional cookie: string

Defined in

src/core/Session.ts:265


http

http: HTTPClient

Defined in

src/core/Session.ts:253


logged_in

logged_in: boolean

Defined in

src/core/Session.ts:254


oauth

oauth: OAuth2

Defined in

src/core/Session.ts:252


player?

optional player: Player

Defined in

src/core/Session.ts:264


po_token?

optional po_token: string

Defined in

src/core/Session.ts:268


user_agent?

optional user_agent: string

Defined in

src/core/Session.ts:256

Accessors

client_name

get client_name(): string

Returns

string

Defined in

src/core/Session.ts:688


client_version

get client_version(): string

Returns

string

Defined in

src/core/Session.ts:684


lang

get lang(): string

Returns

string

Defined in

src/core/Session.ts:692

Methods

addEventListener()

addEventListener(type, callback, options?): void

Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

MDN Reference

Parameters

type: string

callback: null | EventListenerOrEventListenerObject

options?: boolean | AddEventListenerOptions

Returns

void

Inherited from

EventEmitter.addEventListener

Defined in

node_modules/typescript/lib/lib.dom.d.ts:8256


dispatchEvent()

dispatchEvent(event): boolean

Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

MDN Reference

Parameters

event: Event

Returns

boolean

Inherited from

EventEmitter.dispatchEvent

Defined in

node_modules/typescript/lib/lib.dom.d.ts:8262


emit()

emit(type, ...args): void

Parameters

type: string

• ...args: any[]

Returns

void

Inherited from

EventEmitter.emit

Defined in

src/utils/EventEmitterLike.ts:10


off()

off(type, listener): void

Parameters

type: string

listener

Returns

void

Inherited from

EventEmitter.off

Defined in

src/utils/EventEmitterLike.ts:40


on()

on(type, listener)

on(type, listener): void

Parameters

type: "auth"

listener: OAuth2AuthEventHandler

Returns

void

Overrides

EventEmitter.on

Defined in

src/core/Session.ts:278

on(type, listener)

on(type, listener): void

Parameters

type: "auth-pending"

listener: OAuth2AuthPendingEventHandler

Returns

void

Overrides

EventEmitter.on

Defined in

src/core/Session.ts:279

on(type, listener)

on(type, listener): void

Parameters

type: "auth-error"

listener: OAuth2AuthErrorEventHandler

Returns

void

Overrides

EventEmitter.on

Defined in

src/core/Session.ts:280

on(type, listener)

on(type, listener): void

Parameters

type: "update-credentials"

listener: OAuth2AuthEventHandler

Returns

void

Overrides

EventEmitter.on

Defined in

src/core/Session.ts:281


once()

once(type, listener)

once(type, listener): void

Parameters

type: "auth"

listener: OAuth2AuthEventHandler

Returns

void

Overrides

EventEmitter.once

Defined in

src/core/Session.ts:287

once(type, listener)

once(type, listener): void

Parameters

type: "auth-pending"

listener: OAuth2AuthPendingEventHandler

Returns

void

Overrides

EventEmitter.once

Defined in

src/core/Session.ts:288

once(type, listener)

once(type, listener): void

Parameters

type: "auth-error"

listener: OAuth2AuthErrorEventHandler

Returns

void

Overrides

EventEmitter.once

Defined in

src/core/Session.ts:289


removeEventListener()

removeEventListener(type, callback, options?): void

Removes the event listener in target's event listener list with the same type, callback, and options.

MDN Reference

Parameters

type: string

callback: null | EventListenerOrEventListenerObject

options?: boolean | EventListenerOptions

Returns

void

Inherited from

EventEmitter.removeEventListener

Defined in

node_modules/typescript/lib/lib.dom.d.ts:8268


signIn()

signIn(credentials?): Promise<void>

Parameters

credentials?: OAuth2Tokens

Returns

Promise<void>

Defined in

src/core/Session.ts:651


signOut()

signOut(): Promise<undefined | Response>

Signs out of the current account and revokes the credentials.

Returns

Promise<undefined | Response>

Defined in

src/core/Session.ts:674


create()

static create(options): Promise<Session>

Parameters

options: SessionOptions = {}

Returns

Promise<Session>

Defined in

src/core/Session.ts:295


fromCache()

static fromCache(cache, session_args): Promise<null | SessionData>

Retrieves session data from cache.

Parameters

cache: ICache

A valid cache implementation.

session_args: SessionArgs

User provided session arguments.

Returns

Promise<null | SessionData>

Defined in

src/core/Session.ts:327


getSessionData()

static getSessionData(lang, location, account_index, visitor_data, user_agent, enable_safety_mode, generate_session_locally, device_category, client_name, tz, fetch, on_behalf_of_user?, cache?, enable_session_cache?, po_token?, retrieve_innertube_config?): Promise<object>

Parameters

lang: string = ''

location: string = ''

account_index: number = 0

visitor_data: string = ''

user_agent: string = ...

enable_safety_mode: boolean = false

generate_session_locally: boolean = false

device_category: DeviceCategory = 'desktop'

client_name: ClientType = ClientType.WEB

tz: string = ...

fetch = Platform.shim.fetch

on_behalf_of_user?: string

cache?: ICache

enable_session_cache?: boolean = true

po_token?: string

retrieve_innertube_config?: boolean = true

Returns

Promise<object>

account_index

account_index: number

api_key

api_key: string

api_version

api_version: string

config_data?

optional config_data: string

context

context: Context

Defined in

src/core/Session.ts:376