moderator-toolbox-nxg-for-reddit / background/handlers/tabUtils

background/handlers/tabUtils

Functions

broadcastToRedditTabs()

broadcastToRedditTabs(message, label, excludeTabId?, cookieStoreId?): Promise<void>

Defined in: extension/data/background/handlers/tabUtils.ts:70

Sends a message to every open Reddit tab, optionally excluding one tab by ID. When cookieStoreId is given, only tabs in that Firefox container receive the message, so events stay scoped to the container they originated from. Omitting it preserves the all-containers behavior.

Parameters

message

unknown

label

string

excludeTabId?

number

cookieStoreId?

string

Returns

Promise<void>


decodeJWTPayload()

decodeJWTPayload(token): Record<string, unknown>

Defined in: extension/data/background/handlers/tabUtils.ts:24

Decodes the payload of a JWT token without verifying the signature.

Parameters

token

string

A dot-separated JWT string

Returns

Record<string, unknown>


getCookieWithFPIFallback()

getCookieWithFPIFallback(info): Promise<Cookie | null>

Defined in: extension/data/background/handlers/tabUtils.ts:92

Fetches a cookie, retrying with firstPartyDomain: 'reddit.com' if Firefox’s first-party isolation throws on the initial attempt.

Parameters

info

GetDetailsType

Returns

Promise<Cookie | null>


getRedditSessionJTI()

getRedditSessionJTI(storeId?): Promise<string>

Defined in: extension/data/background/handlers/tabUtils.ts:135

Returns the jti (JWT ID) claim from the reddit_session cookie, which changes on account switch and is used to namespace cached OAuth tokens per session. When storeId is given, reads from that Firefox container’s cookie store so tokens are namespaced per container. Returns 'noSessionFallback' when no session cookie is present.

Parameters

storeId?

string

Returns

Promise<string>


getRedditSessionUserID()

getRedditSessionUserID(sender): Promise<string>

Defined in: extension/data/background/handlers/tabUtils.ts:109

Extracts the base36 Reddit user ID from the reddit_session JWT cookie for the tab identified by sender. The sub claim has the form t2_<base36id>; the t2_ prefix is stripped before returning. Returns 'noSessionFallback' when no session cookie is present.

Parameters

sender

MessageSender

Returns

Promise<string>


isAllowedRedditHost()

isAllowedRedditHost(hostname): boolean

Defined in: extension/data/background/handlers/tabUtils.ts:13

Returns true if hostname is reddit.com, redd.it, or any subdomain thereof.

Parameters

hostname

string

Returns

boolean


sendTabMessageSilently()

sendTabMessageSilently(tabId, message, label, options?): void

Defined in: extension/data/background/handlers/tabUtils.ts:48

Sends a message to a tab and silently swallows “no receiving end” errors, which are expected for iframes and pages where Toolbox is not active. Unexpected errors are logged via console.warn with the given label.

Parameters

tabId

number

message

unknown

label

string

options?

SendMessageOptionsType

Returns

void