Skip to content

k.google ​

Google PageSpeed/Lighthouse and Firebase services

Execution ContextPrerequisitesTypical Use
KScript API, Page / View server scriptsValid site Firebase Service Account JSON required (even for Lighthouse root methods)Generating/parsing Lighthouse reports, verifying Firebase tokens, and managing users

k.google groups Google-related capabilities: PageSpeed/Lighthouse methods sit directly on k.google, while Firebase Admin capabilities are exposed under k.google.firebase.

Runtime Configuration Prerequisite

Accessing k.google eagerly initializes k.google.firebase by reading the site's Firebase Service Account JSON credential (requiring type: "service_account", project_id, private_key_id, private_key, client_email, and token_uri). If the site has no configured or valid Firebase credential, any access to k.google (including Lighthouse root methods) throws an exception.

Quick Start ​

js
k.api.get("lighthouse", () => {
  const json = k.google.lHRJson("https://www.kooboo.com", false)
  const report = k.google.parseJson(json)
  return report.getSummary()
})

Quick Reference ​

Method / PropertyDescriptionReturns
lHRJson(absoluteUrl, mobileDevice)Analyze an absolute URL and return Lighthouse JSONstring
lHRUrl(absoluteUrl, mobileDevice)Analyze an absolute URL and return a report URLstring
lHRUrlFromJson(json)Convert Lighthouse JSON into an openable report URLstring
parseJson(json)Parse Lighthouse JSON into FullLHRObjFullLHRObj
saveJson(json) / getJson(id)Temporarily save Lighthouse JSON and retrieve by IDGuid / string | null
shortLhrReportUrl(json)Save JSON and generate a short report URLstring
firebase.verifyIdToken(idToken)Verify a client Firebase ID token and return claimsRecord<string, string>
firebase.createCustomToken(uid)Issue a Firebase custom token for the given uidstring
firebase.createUser / updateUser / deleteUserCreate, update, or delete Firebase Auth usersUserRecord / void
firebase.getUserByEmail / getUserByPhoneNumberLook up a Firebase user by email or phone numberUserRecord
firebase.generate*LinkGenerate verification, password reset, and sign-in linksstring

PageSpeed / Lighthouse ​

lHRJson() / lHRUrl() ​

Generate Lighthouse JSON or an online report URL for an absolute URL.

ParameterTypeRequiredDescription
absoluteUrlstringYesAbsolute URL to analyze
mobileDevicebooleanYesCompatibility parameter; the current request does not switch desktop/mobile strategy based on this value

Returns: lHRJson() returns a Lighthouse JSON string; lHRUrl() returns a /_Admin/LightHouse/index.html?gzip=1#... report URL.

js
const json = k.google.lHRJson("https://www.kooboo.com", false)
const report = k.google.parseJson(json)
const summary = report.getSummary()

return {
  performance: summary.performance,
  accessibility: summary.accessibility,
  bestpractices: summary.bestpractices,
  seo: summary.seo,
  pwa: summary.pwa
}

If you only need an openable Lighthouse report URL:

js
const reportUrl = k.google.lHRUrl("https://www.kooboo.com", true)
return { reportUrl }

lHRUrlFromJson() ​

Convert existing Lighthouse JSON into a report URL that can be opened in Kooboo.

ParameterTypeRequiredDescription
jsonstringYesLighthouse JSON string

Returns: string.

js
const json = k.google.lHRJson("https://www.kooboo.com", false)
const reportUrl = k.google.lHRUrlFromJson(json)
return { reportUrl }

parseJson() / saveJson() / getJson() ​

Parse Lighthouse JSON, save it to temporary storage, and retrieve it by ID.

MethodParameterReturnDescription
parseJson(json)stringFullLHRObjParse Lighthouse JSON
saveJson(json)stringGuidStore JSON in temporary storage and return a Guid ID (use String(id) if a JS string is needed)
getJson(id)anystring | nullRead stored JSON by ID; returns null if not found

Returns: FullLHRObj, temporary report Guid (convert with String(id) if a JS string is needed), or the stored JSON string.

js
const json = k.google.lHRJson("https://www.kooboo.com", false)
const id = k.google.saveJson(json)
const saved = k.google.getJson(id)

return {
  id: String(id),
  saved: !!saved,
  summary: saved ? k.google.parseJson(saved).getSummary() : null
}

shortLhrReportUrl() ​

Save JSON and generate a short report URL (/_api/LightHouse/ReadReport?id=...).

ParameterTypeRequiredDescription
jsonstringYesLighthouse JSON string

Returns: string.

js
const json = k.google.lHRJson("https://www.kooboo.com", false)
const url = k.google.shortLhrReportUrl(json)

return {
  url,
  fullUrl: k.site.info.makeAbsUrl(url)
}

FullLHRObj and ReportSummary ​

parseJson(json) returns FullLHRObj:

MemberTypeDescription
lighthouseResult{ categories }Contains performance, accessibility, bestpractices, seo, and pwa (each with id: string, score: number)
getSummary()() => ReportSummaryMultiplies each category score by 100 to produce an integer summary

ReportSummary properties (note bestpractices is all lowercase):

PropertyTypeDescription
performancenumberPerformance score (0–100)
accessibilitynumberAccessibility score (0–100)
bestpracticesnumberBest Practices score (0–100)
seonumberSEO score (0–100)
pwanumberPWA score (0–100)

Firebase (k.google.firebase) ​

Requires valid Firebase Admin service account JSON configured in the site settings before calling.

verifyIdToken() / createCustomToken() ​

Verify a client Firebase ID token or issue a custom token for a user ID.

MethodParameterReturnDescription
verifyIdToken(idToken)idToken: stringRecord<string, string>Verify ID token and return its claims map
createCustomToken(uid)uid: stringstringGenerate a custom token for the given uid

Returns: verifyIdToken() returns a claims dictionary; createCustomToken() returns the token string.

js
const claims = k.google.firebase.verifyIdToken(idToken)
const customToken = k.google.firebase.createCustomToken(claims.user_id || claims.sub)
return { claims, customToken }

createUser() / updateUser() / deleteUser() ​

Manage Firebase Auth users.

MethodParameterReturnDescription
createUser(user)user: UserRecordArgsUserRecordCreate a Firebase user
updateUser(arg)arg: UserRecordArgsUserRecordUpdate an existing user; uid is required
deleteUser(uid)uid: stringvoidDelete the user with the given uid

UserRecordArgs properties:

PropertyTypeDescription
uidstringUser UID (required for updateUser; optional for createUser)
emailstringEmail address
phoneNumberstringPhone number in E.164 format
displayNamestringDisplay name
emailVerifiedbooleanWhether email is verified
photoUrlstringProfile photo URL
disabledbooleanWhether the account is disabled
passwordstringPassword

Returns: createUser() / updateUser() return UserRecord; deleteUser() returns void.

js
const user = k.google.firebase.createUser({
  email: "alice@example.com",
  password: "SecretPassword123!",
  displayName: "Alice"
})

const updated = k.google.firebase.updateUser({
  uid: user.uid,
  emailVerified: true
})

k.google.firebase.deleteUser(updated.uid)

getUserByEmail() / getUserByPhoneNumber() ​

Look up a user by email or phone number.

MethodParameterReturnDescription
getUserByEmail(email)email: stringUserRecordRetrieve user record by email
getUserByPhoneNumber(phoneNumber)phoneNumber: stringUserRecordRetrieve user record by phone number

Returns: UserRecord.

js
const byEmail = k.google.firebase.getUserByEmail("alice@example.com")
const byPhone = k.google.firebase.getUserByPhoneNumber("+14155550100")

Generate email verification, password reset, and email sign-in links.

MethodParameterReturnDescription
generateEmailVerificationLink(email)email: stringstringGenerate email verification link
generatePasswordResetLink(email)email: stringstringGenerate password reset link
generatePasswordResetLink(email, settings)email: string, settings: ActionCodeSettingsstringSee the overload note below
generateSignInWithEmailLink(email, settings)email: string, settings: ActionCodeSettingsstringGenerate email-link sign-in URL

generatePasswordResetLink 2-Parameter Overload Behavior

In the current runtime, the 2-parameter overload generatePasswordResetLink(email, settings) invokes email-link sign-in generation (equivalent to generateSignInWithEmailLink(email, settings)). Use the 1-parameter generatePasswordResetLink(email) overload to generate a password reset link.

ActionCodeSettings properties:

PropertyTypeDescription
urlstringContinue / deep-link URL
handleCodeInAppbooleanWhether the action code is handled in-app
dynamicLinkDomainstringFirebase Dynamic Links domain
iosBundleIdstringiOS bundle ID
androidPackageNamestringAndroid package name
androidMinimumVersionstringMinimum Android app version
androidInstallAppbooleanWhether to install the Android app if missing

Returns: string, the generated email action URL.

js
const verifyLink = k.google.firebase.generateEmailVerificationLink("alice@example.com")
const resetLink = k.google.firebase.generatePasswordResetLink("alice@example.com")
const signInLink = k.google.firebase.generateSignInWithEmailLink("alice@example.com", {
  url: "https://example.com/finish-signin",
  handleCodeInApp: true
})

UserRecord Properties ​

PropertyTypeDescription
uidstringUnique user ID
displayNamestringDisplay name
emailstringEmail address
phoneNumberstringPhone number
photoUrlstringPhoto URL
providerIdstringProvider ID
emailVerifiedbooleanWhether email is verified
disabledbooleanWhether account is disabled
providerDataIUserInfo[]Linked provider entries
tokensValidAfterTimestampDateToken validity start time
userMetaDataUserMetadataCreation and last sign-in metadata
customClaimsanyCustom claims object
tenantIdstringMulti-tenant ID

TypeScript Definitions ​

Show full TypeScript definitions
ts
interface KGoogle {
  firebase: KFirebase;
  lHRJson(AbsoluteUrl: string, MobileDevice: boolean): string;
  lHRUrl(AbsoluteUrl: string, MobileDevice: boolean): string;
  lHRUrlFromJson(json: string): string;
  parseJson(json: string): FullLHRObj;
  saveJson(json: string): any;
  shortLhrReportUrl(json: string): string;
  getJson(Id: any): string;
}

interface FullLHRObj {
  lighthouseResult: lighthouseResult;
  getSummary(): ReportSummary;
}

interface lighthouseResult {
  categories: categories;
}

interface categories {
  performance: itemResult;
  accessibility: itemResult;
  bestpractices: itemResult;
  seo: itemResult;
  pwa: itemResult;
}

interface itemResult {
  id: string;
  score: number;
}

interface ReportSummary {
  performance: number;
  accessibility: number;
  bestpractices: number;
  seo: number;
  pwa: number;
}

interface KFirebase {
  verifyIdToken(idToken: string): Record<string, string>;
  createCustomToken(uid: string): string;
  createUser(user: UserRecordArgs): UserRecord;
  deleteUser(uid: string): void;
  updateUser(arg: UserRecordArgs): UserRecord;
  generateEmailVerificationLink(email: string): string;
  generatePasswordResetLink(email: string): string;
  generatePasswordResetLink(email: string, settings: ActionCodeSettings): string;
  getUserByEmail(email: string): UserRecord;
  getUserByPhoneNumber(phoneNumber: string): UserRecord;
  generateSignInWithEmailLink(email: string, settings: ActionCodeSettings): string;
}

interface UserRecordArgs {
  uid?: string;
  email?: string;
  phoneNumber?: string;
  displayName?: string;
  emailVerified?: boolean;
  photoUrl?: string;
  disabled?: boolean;
  password?: string;
}

interface IUserInfo {
  uid: string;
  displayName: string;
  email: string;
  phoneNumber: string;
  photoUrl: string;
  providerId: string;
}

interface UserMetadata {
  creationTimestamp?: Date;
  lastSignInTimestamp?: Date;
  lastRefreshTimestamp?: Date;
}

interface UserRecord extends IUserInfo {
  uid: string;
  displayName: string;
  email: string;
  phoneNumber: string;
  photoUrl: string;
  providerId: string;
  emailVerified: boolean;
  disabled: boolean;
  providerData: IUserInfo[];
  tokensValidAfterTimestamp: Date;
  userMetaData: UserMetadata;
  customClaims: any;
  tenantId: string;
}

interface ActionCodeSettings {
  url: string;
  handleCodeInApp?: boolean;
  dynamicLinkDomain?: string;
  iosBundleId?: string;
  androidPackageName?: string;
  androidMinimumVersion?: string;
  androidInstallApp?: boolean;
}