youtubei.js / Session
Class: Session
Defined in: src/core/Session.ts:251
Represents an InnerTube session. This holds all the data needed to make requests to YouTube.
Extends
Constructors
Constructor
new Session(
context
,api_key
,api_version
,account_index
,config_data?
,player?
,cookie?
,fetch?
,cache?
,po_token?
):Session
Defined in: src/core/Session.ts:258
Parameters
context
api_key
string
api_version
string
account_index
number
config_data?
string
player?
cookie?
string
fetch?
{(input
, init?
): Promise
<Response
>; (input
, init?
): Promise
<Response
>; }
cache?
po_token?
string
Returns
Session
Overrides
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
cookie?
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 Signature
get client_name():
string
Defined in: src/core/Session.ts:688
Returns
string
client_version
Get Signature
get client_version():
string
Defined in: src/core/Session.ts:684
Returns
string
lang
Get Signature
get lang():
string
Defined in: src/core/Session.ts:692
Returns
string
Methods
addEventListener()
addEventListener(
type
,callback
,options?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:8256
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.
Parameters
type
string
callback
EventListenerOrEventListenerObject
| null
options?
boolean
| AddEventListenerOptions
Returns
void
Inherited from
dispatchEvent()
dispatchEvent(
event
):boolean
Defined in: node_modules/typescript/lib/lib.dom.d.ts:8262
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.
Parameters
event
Event
Returns
boolean
Inherited from
emit()
emit(
type
, ...args
):void
Defined in: src/utils/EventEmitterLike.ts:10
Parameters
type
string
args
...any
[]
Returns
void
Inherited from
off()
off(
type
,listener
):void
Defined in: src/utils/EventEmitterLike.ts:40
Parameters
type
string
listener
(...args
) => void
Returns
void
Inherited from
on()
Call Signature
on(
type
,listener
):void
Defined in: src/core/Session.ts:278
Parameters
type
"auth"
listener
Returns
void
Overrides
Call Signature
on(
type
,listener
):void
Defined in: src/core/Session.ts:279
Parameters
type
"auth-pending"
listener
Returns
void
Overrides
EventEmitter.on
Call Signature
on(
type
,listener
):void
Defined in: src/core/Session.ts:280
Parameters
type
"auth-error"
listener
Returns
void
Overrides
EventEmitter.on
Call Signature
on(
type
,listener
):void
Defined in: src/core/Session.ts:281
Parameters
type
"update-credentials"
listener
Returns
void
Overrides
EventEmitter.on
once()
Call Signature
once(
type
,listener
):void
Defined in: src/core/Session.ts:287
Parameters
type
"auth"
listener
Returns
void
Overrides
Call Signature
once(
type
,listener
):void
Defined in: src/core/Session.ts:288
Parameters
type
"auth-pending"
listener
Returns
void
Overrides
EventEmitter.once
Call Signature
once(
type
,listener
):void
Defined in: src/core/Session.ts:289
Parameters
type
"auth-error"
listener
Returns
void
Overrides
EventEmitter.once
removeEventListener()
removeEventListener(
type
,callback
,options?
):void
Defined in: node_modules/typescript/lib/lib.dom.d.ts:8268
Removes the event listener in target's event listener list with the same type, callback, and options.
Parameters
type
string
callback
EventListenerOrEventListenerObject
| null
options?
boolean
| EventListenerOptions
Returns
void
Inherited from
EventEmitter
.removeEventListener
signIn()
signIn(
credentials?
):Promise
<void
>
Defined in: src/core/Session.ts:651
Parameters
credentials?
Returns
Promise
<void
>
signOut()
signOut():
Promise
<Response
|undefined
>
Defined in: src/core/Session.ts:674
Signs out of the current account and revokes the credentials.
Returns
Promise
<Response
| undefined
>
create()
static
create(options
):Promise
<Session
>
Defined in: src/core/Session.ts:295
Parameters
options
SessionOptions
= {}
Returns
Promise
<Session
>
fromCache()
static
fromCache(cache
,session_args
):Promise
<SessionData
|null
>
Defined in: src/core/Session.ts:327
Retrieves session data from cache.
Parameters
cache
A valid cache implementation.
session_args
User provided session arguments.
Returns
Promise
<SessionData
| null
>
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
<{account_index
:number
;api_key
:string
;api_version
:string
;config_data?
:string
;context
:Context
; }>
Defined in: src/core/Session.ts:376
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
{(input
, init?
): Promise
<Response
>; (input
, init?
): Promise
<Response
>; }
on_behalf_of_user?
string
cache?
enable_session_cache?
boolean
= true
po_token?
string
retrieve_innertube_config?
boolean
= true
Returns
Promise
<{ account_index
: number
; api_key
: string
; api_version
: string
; config_data?
: string
; context
: Context
; }>